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

Help Me With Local Script Problems?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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
You cannot wait 1/100th of a second. I suggest removing line 2 and changing line 1 to "while wait() do" FearMeIAmLag 1161 — 10y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

Ad

Answer this question