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

How to see if a player has a tool with a tag and delete others?

Asked by 6 years ago
local UT = game.Players.LocalPlayer.Backpack:findFirstChild("Tool").UtilityTag
         if UT == nil then --IDK what I'm actually doing but I'm just trying to see if that player's tool has the tag (it's a frame).
            print("true")
        else
            print("false")
        end

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Assuming I read your question right, you can't use Tool as what you are looking for, you need to check if the class is a tool, but finding tool would be too much for the server because there might be more than one tool. You should use this script:

for i, v in pairs(game.Players.LocalPlayer.Backpack:GetChildren())
    if v:IsA("Tool") do
        if not v:FindFirstChild("UtilityTag") then
            v:Destroy()
        end
    end
end

What that means in English is

check everything inside the local player's backpack, if the part we are checking is a tool, then if you can't find a utility tag, then destroy it.

Hope I helped.

Ad
Log in to vote
0
Answered by 6 years ago

Thanks @cmgtotalyawesome there were a few errors in your script through.

        for i, v in pairs(game.Players.LocalPlayer.Backpack:GetChildren()) --Needed a ")"
        do if v:IsA("Tool") then --"Do" needed apparently
            if not v:FindFirstChild("UtilityTag") then
                v:Destroy()
                end
            end
        end --No ")" needed.

Thanks btw! :D

0
sorry, I was doing functions all day and got used to just 3 parentheses and a parentheses around the last end xD cmgtotalyawesome 1418 — 6y

Answer this question