|
| 15 Feb 2016 04:06 PM |
Hey, so I'm working on this game that has a GUI where you equip weapons using buttons. Every button has a script inside of it that looks like this:
local target = script.Parent.Parent.Parent:FindFirstChild("TextButton") --[[locates "Play" button ]]--
local weapon = target:FindFirstChild("goal") --finds the string value I need to change
function onClicked(GUI) weapon.Value = "Axe" -- changes the value end
script.Parent.MouseButton1Click:connect(onClicked) -- runs the above function on click
So far, this is perfect in Studio, but the second I test it in real roblox, nothing works. The problem is with line 2, it say "target" is a nil value?
I was wondering if someone could figure out what's wrong, it's driving me crazy.
BTW, this is in a local script, so... |
|
|
| Report Abuse |
|
|
| 15 Feb 2016 04:09 PM |
Try putting this at the start:
repeat wait() until script.Parent.Parent.Parent:FindFirstChild('TextButton')
|
|
|
| Report Abuse |
|
|
| 15 Feb 2016 04:12 PM |
Ok, that seems to have fixed it, thanks!
So I'm assuming it was a problem with the loading process? |
|
|
| Report Abuse |
|
|
| 15 Feb 2016 04:14 PM |
WaitForChild
http://wiki.roblox.com/index.php?title=API:Class/Instance/WaitForChild |
|
|
| Report Abuse |
|