script.Parent.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then hit.Parent.Part.Sword.Equipped=true end end)
Sometimes the hit part's Parent
will not be your Character
( Handles of accessories for example, have their Parent as said accessory, and not your Character ) for this reason it's safer to first check if it has a Humanoid
as a Parent
, and then, use GetPlayerFromCharacter
, like this:
Players = game:GetService("Players") --Gets Player service Rep = game.ReplicatedStorage script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then --Checks if Toucher has a Humanoid local Player = Players:GetPlayerFromCharacter(hit.Parent) -- Gets Player if Rep:FindFirstChild("Sword") and not Player.Character:FindFirstChild("Sword") then local Sword = Rep.Sword:Clone() Sword.Parent = Player.Character end end end)
But this might not be the only problem, you should have to check the Tool's name, if it exists, and more to make sure this works properly.
Also, make sure you put all of your code inside a lua Box, like this:
"~~~~~~~~~~~~~~~~~"
--Code
"~~~~~~~~~~~~~~~~~"
( Without the quotations, of course, it would look this: )
--Code
Hope this helps!