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!

3 comments
Is this this a regular script or local script, and also is this FE?
Remove the return statement inside the function. It is not needed.
Crazycat, it's a regular script. No FE, but planning on changing it later.