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

Help Me With Local Script Problems?

This script is a local script thats inside a local script thats inside a gui. The script is testing if you have a sword if its true then it will disable the shop script so it you can't buy it twice.

while true do
wait(0.01)
if game.Players.LocalPlayer.BackPack.LongSword == nil or game.Players.LocalPlayer.Character.LongSword == nil then
	script.Parent.Disabled = true
	script.Parent.Parent.Text = "Own"
end
end

1 comment

1

You cannot wait 1/100th of a second. I suggest removing line 2 and changing line 1 to "while wait() do"

1 answer

✓ Accepted answer

Children are not nil. If a child doesn't exist and you try to access it, ROBLOX will throw an error.

Use :FindFirstChild("ObjName") instead, which will return nil when the object doesn't exist.


wait will wait for at least a 30th of a second, you might as well use wait(0) or wait() if you intend as quickly as possible.


I'm not sure why you would use or in this particular case. Unless the player has two copies of the sword, one wielded and one not, the condition will always be true.

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