Help attempt to index nil with 'Visible'

Basically means in this line:

Workspace.Wood Crate.Script:60:

Is a long running script.

It still the same error like before

Which error? If its the exhaustion time then send me the script inside workspace.Crate line 60.

what i have to do to fix that ? delete that script

yes its error at line workspace.Crate line 60

U misspelt ScriptTimeoutLenght length.

how can I misspelt I literally copy it from you

i need to run it when before the game start or when the game start ?

So few things:

Could u specify the error msg

If it is exhaustion time send me the script inside workspace.WoodCrate

Is my code causing th error.

okay when i typed the run bar code is working properly but there is error that same with the title of this post. Its attempt to index nil with ‘Visible’

Hello did you found any way to fix this thing ?

while hatfound == false do
		for i,v in pairs(hatModule.rarities) do
			if math.random(1,v) == hatNumber then
				local str = hatModule.hats[i].Name
				hat = str:gsub(" ", "")
                hatfound = true 
			end
		end
	end

@Luaxkw must work now

if findfirstcild finds nothing then it returns nil end

local found = parent:FindFirstChild('name')
if found then
print'something if found'
else
print'nothing is found'
end

Did you try it in studio before you post it in devforum ?

Hi there, I am wondering why you look for UIS in the starterGui. Starter gui is used for the local scripts, and you should enter player.PlayerGui instead. I am not sure if this works, but try.

The issue comes because the file you are looking for is not declared properly

local player = game.Players.LocalPlayer
local clickdetector = script.Parent.ClickDetector
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataModule = require(ReplicatedStorage:WaitForChild("DataModule"))
local hatModule = require(ReplicatedStorage:WaitForChild("HatModule"))
local hatname = ReplicatedStorage:WaitForChild("Hats")
local hatimgplace = player:WaitForChild("PlayerGui").CrateGui.HatsImage

local hatInventory = {}


local function ChosenHat(player)
	
	local playerGui = player:WaitForChild("PlayerGui")
	local CrateGui = playerGui.CrateGui
	local crateIcon = CrateGui.cratehatch
	
	local timer = tick()
	
	crateIcon.Visible = true
	
	while tick() - timer < DataModule.CrateOpeningLenght do
		wait(.1)
		crateIcon.Rotation = math.random(-9,9)
	end
	
	
	

	
	crateIcon.Visible = false
	local hatNumber = math.random(1,100)
	local hatfound = false
	local hat = nil
	while hatfound == false do
		for i,v in pairs(hatModule.rarities) do
			if math.random(1,v) == hatNumber then
				hatfound = true
				hat = i
			end
		end
	end
	
	
	crateIcon.Visible = false
	local hatImage = hatimgplace:FindFirstChild(hat)
	hatImage.Visible = true --error
	wait(2)
	hatImage.Visible = false -- also this I think
		
	
	return hat
	
end

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	
	if player.leaderstats.Robux.Value >= DataModule.CommonCrateCost  then
		player.leaderstats.Robux.Value = player.leaderstats.Robux.Value - DataModule.CommonCrateCost
		
		local hatOpened = ChosenHat(player)
		
		print(hatOpened)
		
		local hats = hatname:FindFirstChild(hatOpened):Clone()
		table.insert(hatInventory, hatOpened)
		print(hatInventory)
		hatOpened.Parent = player
	end
end)

i already did it but can it works if I put it :WaitForChild

Yes, as it will wait with loading until it has found the specific item you are looking for.

I cant, i hav school work thts why the results rnt always accurate, its pure guesswork. I hope u understand.

P.S I hope i fixed it now, heres the code to replace.

while hatfound == false do
		for i,v in pairs(hatModule.rarities) do
			if math.random(1,v) == hatNumber then
				local item = hatModule.hats[i]
                local str = math.random(1, #item).Name
				hat = str:gsub(" ", "")
                hatfound = true 
			end
		end
	end

Also one thing, try to make ur hatimg name corresponding to the hat name. My code will fix tht, except for ur redsparkletime fedora or smth

His issue is a issue with a ui calling nil, not his handler.

Hey guys I got an error Its Workspace.Wood Crate.Script:7: attempt to index nil with ‘WaitForChild’ I dont know how this happened