Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

3 comments

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

0

thanks but din't work

1 answer

✓ Accepted answer

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.

4 comments

0

thankyou, i din't need the playeradded i just added the script inside my script it works fine

0

However, you'll want to do game:GetService("Players") instead of game.Players

0

oh ok

0

ok it works thx

This discussion is preserved as it was. New answers, comments, and votes are closed.