My other question got taken down because some kid reported it for no reason.My script won't work I tried fixing it on my own and it still won't work. Please help. Thanks. Also, here's more details i'm trying to do is when a player touches the brick he/she will get a gear. Here's the script.
local spam_prevention = false script.Parent.Touched:connect(function(hit) print IsPlayer = hit.Parent.Parent:FindFirstChild("Humanoid") if IsPlayer ~= nil then if spam_prevention == false then spam_prevention = true end Tool_To_Give = game.Lighting.Dynamite:Clone() player_ = game.Players[hit.Parent.Parent.Name] Tool_To_Give.Parent=player_.Backpack wait(1) spam_prevention=false end end)
Thanks
:NOTE I don't want a replacement of this script I just want help. Also, I didn't free model it. If anyone in the comments say I did don't listen to them they're just haters. Bye! :)
local spam_prevention = false script.Parent.Touched:Connect(function(hit) if spam_prevention == true then return end spam_prevention = true print("Touched") local IsPlayer = hit.Parent:FindFirstChild("Humanoid") if IsPlayer ~= nil then local player_ = game.Players[hit.Parent.Name] if player_.Backpack:FindFirstChild("Dynamite") == nil then local Tool_To_Give = game.ServerStorage.Dynamite:Clone() Tool_To_Give.Parent = player_.Backpack wait(1) end end spam_prevention = false end)
I assume "spam prevention" is meant to be a debounce, so it should be rewritten as above.
Next, the player's character is the hit's Parent. hit.Parent.Parent refers to the workspace.
Objects should also be placed into the ServerStorage instead of Lighting to reduce lag and unwanted issues.
You also have a random print
which is doing nothing. If you use the script anaysis window you would be able to catch this error.
connect
is considered deprecated, use Connect
instead.