Hello. I am currently making a game which is taking a LOT of coding, therefore I have a TON of errors. This time, I made a script where when the character touches a part of a model, it gives the player a tool. I do not want anything else but a fix for this script.
Here is the script:
db = false function OnTouched(hit) if hit.Parent:FindFirstChild("Humanoid") and db == false then db = true local wep = script.Parent.Parent--(change this part if needed, needs to find the name of the model) local clone = game.ReplicatedStorage.Weapons:FindFirstChild(wep.Name):Clone() clone.Parent = game.Players:FindfirstChild(hit.Parent.Name).Backpack wep:remove() return db == false end end script.Parent.Touched:connect(OnTouched)
Extra Information:
The tool is inside a folder called "Weapons", which is in the ReplicatedStorage. The tool and model have the same name. The model contains two parts: one for the mesh and one for the script. The script part is larger than the mesh part. Both parts have CanCollide off.
And, Thanks!
Try this instead.
db = false script.Parent.Touched:connect(function(hit) player = game.Players:GetPlayerFromCharacter(hit.Parent) -- finds player if player and player:IsA("Player") and db == false then -- you don't have to check for Humanoid, just check if it's a Player. db = true local wep = script.Parent.Parent local clone = game.ReplicatedStorage.Weapons:FindFirstChild(wep.Name):Clone() clone.Parent = player.Backpack db = false end end)