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

Where do I get the precise name of a hat in roblox studio?

Asked by
Peeshavee 226 Moderation Voter
8 years ago

It's sort of hard to explain. What I mean is, if I want to detect if someone's wearing a hat when they enter a game, the script will know it's that hat. I have the script done, but each time I want to know the name of the hat, I have to keep entering the game, checking what the player is wearing and then copy letter by letter. For example:

local hat = hit.Parent:FindFirstChild("SnipersVisor")

If I put Snipers Visor, it wouldn't work. And I wouldn't know that it would be together. So does anyone know where I could get the name?

0
You can check the class name or use IsA. User#5423 17 — 8y

1 answer

Log in to vote
2
Answered by
soved 69
8 years ago

Here this should work.

-- ServerScript.

local PLAYERS = game:GetService("Players")

PLAYERS.PlayerAdded:connect(function(Plr)
    Plr.CharacterAppearanceLoaded:connect(function(Char)
        for i, v in pairs(Char:GetChildren()) do
            if v:IsA("Hat") then
                -- Do whatever you want here.
            end
        end)
    end)
end)
0
Roblox is currently adding a new `Instance:FindFirstChildOfClass(class)` method; It should be around soon. No more looping through all the children to find a single hat! Link150 1355 — 8y
Ad

Answer this question