Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i check if there is a tool in character?

Asked by
CjayPlyz 643 Moderation Voter
6 years ago
Edited 6 years ago

i need a script so that if a a object with a class name of "tool" is inside a player character it deletes it

i have this script but it does't do anything

        local player = game.Players.LocalPlayer
        local character = player.Character
        local child = character:GetChildren()
        if child.ClassName == "Tool" then
            child:delete()
        end

no errors in the output, this is a part of a local script inside the text button

0
i need this for a shop script i have, it delets everything in player backpack but when an tool is equipped the tool is inside the character so i cant delete it CjayPlyz 643 — 6y
0
thanks but din't work CjayPlyz 643 — 6y

1 answer

Log in to vote
4
Answered by
Elixcore 1337 Moderation Voter
6 years ago

ServerScript (Script):

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i,v in pairs(character:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
end)
end)

--[[ what this does is when a player joins the game and gets it's character it checks if it has a tool equipped.if it has a tool equipped it deletes it, to make it check for tools only a certain time you can just add something that uses this script]]

LocalScript:

player = game.Players.LocalPlayer
character = player.Character
for i,v in pairs(character:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end

-- this script does the same thing as above. only checks the first time the player joins.
0
thankyou, i din't need the playeradded i just added the script inside my script it works fine CjayPlyz 643 — 6y
0
However, you'll want to do game:GetService("Players") instead of game.Players sweetkid01 176 — 6y
0
oh ok CjayPlyz 643 — 6y
0
ok it works thx CjayPlyz 643 — 6y
Ad

Answer this question