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

Help With Detection Script?

Asked by
Scootakip 299 Moderation Voter
8 years ago
while true do
    wait()
    local player = game.Players.LocalPlayer
    local plr = game.Players.LocalPlayer.Character
    if player then
        if plr then
            if player.HatEquiped.Value ~= "Empty" then
                for i,v in pairs(plr:GetChildren()) do
                    if v.ClassName == "Hat" then
                        local verification = v:FindFirstChild("HatVerifier")
                        if verification then
                            local hatwearing = v.Name
                            if player.HatEquiped.Value ~= hatwearing then
                                v:Destroy()
                                local hatnowwearing = game.ReplicatedStorage:FindFirstChild(""..player.HatEquiped.Value..""):Clone()
                                if hatnowwearing then
                                    hatnowwearing.Parent = plr
                                end
                            end
                        elseif verification == nil then
                            local hatnowwearing = game.ReplicatedStorage:FindFirstChild(""..player.HatEquiped.Value..""):Clone()
                                if hatnowwearing then
                                    hatnowwearing.Parent = plr
                                end
                        end
                    end
                end
            end
        end
    end
end

The specific issue is on line 21, it says that it's trying to detect a nil value

Basically, this is a script for character customization in my game. Each hat in my game has a value in it to distinguish it from Roblox Avatar hats. In line 21 it tries to make a value to Clone a hat from Replicated Storage if it's name is the same as the value of the hat that the character is supposed to be wearing. I tried to use FindFirstChild so that it wouldn't have the issue, but it is anyways. Help?

1 answer

Log in to vote
0
Answered by 8 years ago

Insufficient. Show me the hierarchy and tell me the data type.

0
The data type isn't important as it's just there (with no value in it) to show that the hat is part of my game. Scootakip 299 — 8y
0
Also, the hierarchy isn't important either, as this follows the hierarchy perfectly. It just has some issues with FindFirstChild giving errors. Scootakip 299 — 8y
Ad

Answer this question