Ok, I made the weapon spawner script over and i added the cooldown with the debounce but the script wont work whats the problem?
ToolName = "TMP" -- Exact name of the weapon/tool RespawnTime = 6 Debounce = false script.Parent.Touched:connect(function(hit) if Debounce == false then Debounce = true p = game.Players:playerFromCharacter(hit.Parent) if p == nil then return end else Wep = game.Lighting.TMP:Clone() --Change TMP to the name of your weapons if p.Backpack:findFirstChild(Wep.Name) ~= nil then return end else Wep.Parent = p.Backpack end end wait(RespawnTime) Debounce = false end end)
Indent in a more organized fashion! You'll be denoted as a more organized and professional scripter.
ToolName = "TMP" -- Exact name of the weapon/tool RespawnTime = 6 Debounce = false script.Parent.Touched:connect(function(hit) if Debounce == false then Debounce = true p = game.Players:playerFromCharacter(hit.Parent) if p == nil then return end else Wep = game.Lighting.TMP:Clone() --Change TMP to the name of your weapons if p.Backpack:findFirstChild(Wep.Name) ~= nil then return end else Wep.Parent = p.Backpack end end wait(RespawnTime) Debounce = false end end) -- I just realized your script contained an error. Nope nope nope nope nope nope...
Let's redo the script. The objective here is to, given the ToolName
, clone the desired weapon and place it in the toucher's backpack - assuming that it is a player.
ToolName = "TMP" RespawnTime = 6 Debounce = false script.Parent.Touched:connect(function (Hit) if not Debounce then Debounce = true -- Where the cloning takes place wait(RespawnTime) Debounce = false end end)
Let's wrap the "if" statement (with the Debounce
as its condition) into another "if" statement that makes sure that the toucher is a) a valid character, b) is part of a player instance, and c) is (preferably) alive.
ToolName = "TMP" RespawnTime = 6 Debounce = false script.Parent.Touched:connect(function (Hit) local HumanoidIsFound = Hit.Parent:FindFirstChild("Humanoid") local PlayerIsFound = game.Players:GetPlayerFromCharacter(Hit.Parent) if Hit.Parent and HumanoidIsFound and HumanoidIsFound.Health > 0 and PlayerIsFound then if not Debounce then Debounce = true local Weapon = game.ServerStorage:FindFirstChild(ToolName) if Weapon then local newWeapon = Weapon:Clone() newWeapon.Parent = PlayerIsFound.Backpack else print("No such weapon named as " .. ToolName .. " in game.ServerStorage.") Debounce = false return -- In my opinion, lines 15-18 are pointless, but it's good to know what's wrong with your script. This is here just in case if the weapon does not exist. end wait(RespawnTime) Debounce = false end end end)
Any questions? Comments? Feel free to ask.