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

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

Asked by 9 years ago

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!

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) secretassassin3 30 — 9y

1 answer

Log in to vote
1
Answered by
Hexcede 52
9 years ago

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

0
The second one works if you change characterBits to tools in line 3. Thanks! secretassassin3 30 — 9y
1
fixed it Hexcede 52 — 9y
Ad

Answer this question