Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script not working with "WaitForChild"?

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

✓ Accepted answer

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

1 comment

0

Okay, they should change it so it also detects other things besides things getting created :/

This discussion is preserved as it was. New answers, comments, and votes are closed.