Ad
Log in to vote
1

A script that removes a tool on touch of a part

Asked by
Exsius 162
7 years ago

I tried doing

script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
game.Players[hit].Backpack.Key:Destroy()
end
end)

but it didn't work and I used the same name "Key for the tool" any help will be truly appreciated

Thanks,

Exsius,

1
Your problem would have to be the name of the "Key" as the rest of your script works. If the player can hold the "Key" then you may also want to check their character as that's where tools that are being held are. Everesty 1001 — 7y
0
Where do I check I can't find "characters" Exsius 162 — 7y

1 answer

Log in to vote
1
Answered by
Shawnyg 4251 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
7 years ago
toolname = "Tool name"
script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
    char = hit.Parent
    plr = game.Players:GetPlayerFromCharacter(char)
    if plr.Backpack:findFirstChild(toolname) then
        plr.Backpack[toolname]:Destroy()
    end
end
end)

-Thank me by accepting this answer/bumping up my reputation!

0
That wouldn't work if they were holding the tool. Thewsomeguy 448 — 7y
Ad

Answer this question