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

Help With Detection Script?

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

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

2 comments

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.

0

Also, the hierarchy isn't important either, as this follows the hierarchy perfectly. It just has some issues with FindFirstChild giving errors.

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