|
| 21 Mar 2013 06:17 PM |
I have a script for something and it has a value inside of it that I need for the script. When the script opens, it says this.
local Value = script.Value.Value
When I start the script, the first thing the output says is "Value is not a valid member of script", and it is. What could be the reason for it saying this??? Thanks. |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 06:20 PM |
local player = script.Parent local CarNum = script.Value local NumPlyr = script.NumPlyr.Value
function firstfunction() if game.Workspace.Starting == true then local Car = game.Lighting.CarNum,NumPlyr:clone() Car.Parent = player wait (1) repeat wait () until player ~= nil and CarNum ~= nil and NumPlyr ~= nil end end
|
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 06:26 PM |
| Btw the script is inside of your player. |
|
|
| Report Abuse |
|
|
wetrel
|
  |
| Joined: 19 Jun 2009 |
| Total Posts: 919 |
|
|
| 21 Mar 2013 06:38 PM |
Well is the Value inside of the script, or does the value have the same parent as the script?
|
|
|
| Report Abuse |
|
|
wetrel
|
  |
| Joined: 19 Jun 2009 |
| Total Posts: 919 |
|
|
| 21 Mar 2013 06:41 PM |
| I suggest that if you ever have an item called "Value" change the name to like "Val" or something. And, "local CarNum = script.Value" goes to the item named "Value". It needs to be "local CarNum = script.Value.Value". But change the vlue name to val for simplicity, my suggestion. |
|
|
| Report Abuse |
|
|
wetrel
|
  |
| Joined: 19 Jun 2009 |
| Total Posts: 919 |
|
|
| 21 Mar 2013 06:42 PM |
| The 3rd word on last line should be "Value". Typing error. |
|
|
| Report Abuse |
|
|
wetrel
|
  |
| Joined: 19 Jun 2009 |
| Total Posts: 919 |
|
|
| 21 Mar 2013 06:45 PM |
| And, on another note, I don't think "if game.Workspace.Starting == true then" will work. Im not usre if that gives you an error, or always makes the statement true but.. It should be: if game.Workspace:findFirstChild("Starting") ~= nil then. It needs to look for the "Starting". the findfirstchild tells it to look for it, and ~= nil makes it look for it to be anything but nil. |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 06:51 PM |
local player = script.Parent local CarNum = script.CarNum.Value local NumPlyr = script.NumPlyr.Value
function firstfunction() if game.Workspace:findFirstChild("Starting") ~=nil then local Car = game.Lighting.(CarNum)(NumPlyr):clone() Car.Parent = player wait (1) repeat wait () until player ~= nil and CarNum ~= nil and NumPlyr ~= nil end end
Thanks what you said helps a lot, but on more thing, where is says "local Car = game.Lighting.(CarNum)(NumPlyr):clone()" will the script read that as "a1" if CarNum = a and NumPlyr = 1 or is there a different way to do that? |
|
|
| Report Abuse |
|
|
wetrel
|
  |
| Joined: 19 Jun 2009 |
| Total Posts: 919 |
|
|
| 21 Mar 2013 06:59 PM |
If you have like a part or a script or something in lighting and you have the name in value for such as... MYVALUE = game.Lighting.Car and you want to use that name then: game.Lighting[MYVALUE.Name]:Clone() |
|
|
| Report Abuse |
|
|
wetrel
|
  |
| Joined: 19 Jun 2009 |
| Total Posts: 919 |
|
|
| 21 Mar 2013 07:09 PM |
local player = script.Parent local CarNum = script.CarNum.Value local NumPlyr = script.NumPlyr.Value
function firstfunction() if game.Workspace:findFirstChild("Starting") ~=nil then local Car = game.Lighting[CarNum.Name][NumPlyr.Name]:clone() Car.Parent = player wait (1) repeat wait () until player ~= nil and CarNum ~= nil and NumPlyr ~= nil end end |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 07:26 PM |
That's close... In Lighting there is a car named a1, then a2, a3, a4, ect. until a8. When a player gets on it inserts this script and the values into the player, then the value "NumPlyr" goes up by 1. Then when the next player gets on, they have NumPlyr.Value = 2. I want the name on the script to be the same as "CarNum" and "NumPlyr" and since CarNum.Value = a and NumPlyr.Value = 1 it finds "a1" in Lighting, clones it, and puts it into your player. Thanks. |
|
|
| Report Abuse |
|
|
wetrel
|
  |
| Joined: 19 Jun 2009 |
| Total Posts: 919 |
|
|
| 21 Mar 2013 07:33 PM |
| Im not understanding you, sorry. |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 21 Mar 2013 07:42 PM |
What you want then is string concatenation. I fixed your code for you, tell me if it still errors:
local player = script.Parent local CarNum = script.CarNum local NumPlyr = script.NumPlyr
function firstfunction() if game.Workspace.Starting then --[[You can nix the '== true', that's the default expression]] local Car = game.Lighting[CarNum.Value .. NumPlyr.Value]:Clone() --[[Concatenate the name/number]] Car.Parent = player wait (1) while wait() do if player and CarNum and NumPlyr then break end --[[Same functionality as your repeat..until, but less likely to break your code without erroring. Trust me, never use repeat..until loops.]] end end end |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 07:44 PM |
Every player has 2 different values in them. I want this script to get the 2 values, put them together, and find the name that they make in Lighting.
For example, if the value of one was "a", and the other was "1", then I want it to find the model "a1" in Lighting, clone it, and insert it to your player. |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 07:44 PM |
> if game.Workspace.Starting then --[[You can nix the '== true', that's the default expression]]
That wouldn't really work. If it's a value, you need to check the value. If it's an instance, you would use FindFirstChild().
(╯°□°)> KMXD
|
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 07:46 PM |
| Wait I haven't tried that just, I posted that last thing before I saw your post. Let me see if it works, thanks. |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 21 Mar 2013 07:50 PM |
No, it works fine.
Test it yourself if you don't believe me, it's called 'truthyness'. All non-nil Objects are 'truthy' in that they will equate to 'true' in a Boolean conditional. |
|
|
| Report Abuse |
|
|
777MrEpic
|
  |
| Joined: 17 Oct 2012 |
| Total Posts: 3998 |
|
| |
|
|
| 21 Mar 2013 07:54 PM |
@Adark
No, I know how booleans work. But assuming it's a value, you would have to check the value:
> if Game.Workspace.Starting.Value then
(╯°□°)> KMXD |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 07:56 PM |
| It isn't working but it isn't giving me errors ether... How does this script start running with "if game.Workspace.Starting then" because what I want it to do is when the BoolValue in workspace named "Starting" turns true the car will spawn. |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 07:58 PM |
Like I said, you would check the value. But if you want the function to fire once the bool turns true, you would connect it with a connection line.
Workspace.Starting.Changed:connect(firstfunction)
(╯°□°)> KMXD
|
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 21 Mar 2013 07:58 PM |
Slang for 'remove'.
Do you even Google? |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 08:00 PM |
| Ok awesome!! But would that also run the function if it turned false? |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2013 08:01 PM |
Yes, but if you change the if statement to check for the value like I did, you would be checking if it's true, but if it turns false, it won't continue to the rest of the code.
(╯°□°)> KMXD |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 21 Mar 2013 08:04 PM |
local player = script.Parent local CarNum = script.CarNum local NumPlyr = script.NumPlyr
function firstfunction() if not game.Workspace.Starting.Value then return end local Car = game.Lighting[CarNum.Value .. NumPlyr.Value]:Clone() Car.Parent = player wait (1) while wait() do if player and CarNum and NumPlyr then break end end end game.Workspace.Starting.Changed:connect(firstfunction)
Full code for you. |
|
|
| Report Abuse |
|
|