script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent)
then hit.Parent.Part.Sword.Equipped=true
end
end)
This script is about touching a part and then getting a sword but it doesnt work,why?
1 answer
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!
5 comments
this doesnt work
What error is it giving? i might be able to fix it
The error is: Part is not a valid member of Model
Ok, i edited my script. Now try putting your tool in the ReplicatedStorage and making sure it has Sword as its name, and it should equip it just fine
Thanks Dude
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
please fix the lua box.
what is a lua box?