Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script not working with "WaitForChild"?

Asked by
lomo0987 250 Moderation Voter
9 years ago

At line 6 the script stops. What should be happening is when a player takes a tycoon, it defines the tycoon within Workspace.

The script works fine but it just ends at line 6. Maybe I did it wrong? This is a normal script within a GUI. Just want to know if I set the WaitForChild wrongly.

It does define owner as the player and the tycoon when it gets claimed is exactly the same as what line 6 is looking for.

wait(2)
Name = script.Parent.Parent.Subject
owner = script.Parent.Parent.Parent.Parent.Parent.Parent
print("Found Owner!")
print(owner)
t = game.Workspace:WaitForChild(owner.Name.."'s Tycoon!") -- doesn't go past this.
-- repeat wait() until t (This was a test, didn't really fix it)
print("Found the tycoon!")
Grading = t.p:FindFirstChild(Name.Value.."drop")
improve = Grading.Drops.Need
using = false

script.Parent.MouseButton1Click:connect(function()
    if using == false then
        using = true
        if improve.Value == script.Parent.Limit.Value then
            script.Parent.BackgroundColor3 = BrickColor.Red()
        else
            improve.Value = improve.Value - 1
        end
    using = false
    end
end)

1 answer

Log in to vote
2
Answered by 9 years ago

If you have another script changing the name of the tycoon in the workspace to reflect the new owner's name, note that WaitForChild does not detect name changes. Repeatedly call "FindFirstChild" instead:

while true do
    t = workspace:FindFirstChild(owner.Name .. "'s Tycoon!")
    if t then break end
    wait()
end
0
Okay, they should change it so it also detects other things besides things getting created :/ lomo0987 250 — 9y
Ad

Answer this question