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

1local player = game.Players.LocalPlayer
2local character = player.Character
3local child = character:GetChildren()
4if child.ClassName == "Tool" then
5    child:delete()
6end

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):

01game.Players.PlayerAdded:Connect(function(player)
02player.CharacterAdded:Connect(function(character)
03for i,v in pairs(character:GetChildren()) do
04if v:IsA("Tool") then
05v:Destroy()
06end
07end
08end)
09end)
10 
11--[[ 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:

1player = game.Players.LocalPlayer
2character = player.Character
3for i,v in pairs(character:GetChildren()) do
4if v:IsA("Tool") then
5v:Destroy()
6end
7end
8 
9-- 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