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

How to check if a player has a tool? [SOLVED]

I am trying to make a minigame when one player has a tool and leads the other players with this tool. I made buttons that should close doors when the player with the tool clicks them, but I can't figure out how to check if a player has a certain tool.

Thanks!

1 comment

0

local button = script.Parent door1 = game.Workspace.Doors.Door1 function onClicked(playerWhoClicked) local playerWhoClicked = button.Click if playerWhoClicked.Backpack.MakeItRain then door1.Transparency = .2 door1.CanCollide = true end end script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

✓ Accepted answer

secretassassin3, Use this for if the tool should be selected.

local button = script.Parent
door1 = workspace.Doors.Door1
function onClicked(playerWhoClicked)
	local characterBits = playerWhoClicked.Character:GetChildren() -- The different parts of the character.
	for i, bit in pairs(characterBits) do
		if bit.ClassName == "Tool" then -- Or change ".ClassName == 'Tool'" to ".Name == 'the name of the tool here'" to make it so that only that tool closes the door.
			door1.Transparency = .2
			door1.CanCollide = true
		end
	end
end

Use this for if the tool should not be selected.

function onClicked(playerWhoClicked)
	local tools = playerWhoClicked.Backpack:GetChildren() -- The different parts of the character.
	for i, tool in pairs(tools) do
		if tool.ClassName == "Tool" then -- Or change ".ClassName == 'Tool'" to ".Name == 'the name of the tool here'" to make it so that only that tool closes the door.
			door1.Transparency = .2
			door1.CanCollide = true
		end
	end
end

Sincerely, crazycittykat

2 comments

0

The second one works if you change characterBits to tools in line 3. Thanks!

1

fixed it

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