Help with class name error

  1. **What do i want to fix? ** I want my error to be fixed

  2. What is the issue? My issue is that this error is keep poping up which is: Players.itzmerose_12.PlayerGui.tools_gui.tools_frame.ScrollingFrame.arranger:10: attempt to index nil with ‘ClassName’

  3. What solutions have you tried so far? I have tried looking in dev forum which any method didn’t work for me and i tried seeing the dev hub but still it didnt work for me.I also tried using ‘IsA()’ but it still didn’t work

game.ReplicatedStorage.Remotes.PlayerLoaded:FireServer()
print("PlayerLoaded")
local player = game.Players.LocalPlayer
local number = 1
game.ReplicatedStorage.Remotes.BeginArrangement.OnClientEvent:Connect(function()
	print("Got")
	repeat
		local image = game.ReplicatedStorage.ToolsImage:FindFirstChild(number)
		if image:ClassName("ImageLabel") then
			print(image.Name)
			local clone = game.ReplicatedStorage.Template:Clone()
			clone.ToolImageDisp.ImageLabel.Image = image.Image
			clone.Name = image.Name
			clone.CostDisplay.Value = image.Cost.Value
			clone.ToolName.Value = image.ToolName.Value
			clone.Parent = script.Parent
			clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(0,0,0) 

			if clone.Name == "1" then
				local sidemenu = script.Parent.Parent
				sidemenu.tool_img.Image = image.Image
				sidemenu.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
				sidemenu.status.Text = "Equip"
				sidemenu.price.cost.Value = 0
				sidemenu.price.Text = "Cost : 0"
				sidemenu.name.Text = clone.ToolName.Value

			end

			if player.OwnedItems:FindFirstChild(clone.ToolName.Value) then
				clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(255,255,255)
			end

			local equipped = player:WaitForChild("Equipped")
			if equipped.Value~= nil then
				if clone.ToolName.Value == equipped.Value then
					script.Parent.tool_img.Image = image.Image
					script.Parent.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
					script.Parent.ststus.TextButton.Text = "Equipped"
					script.Parent.price.Cost.Value = clone.CostDisplay.Value
					script.Parent.price.Text = "Cost : "..script.Parent.price.cost.Value
					script.Parent.name.Text = clone.ToolName.Value
					game.ReplicatedStorage.Remotes.EquipTool:FireServer(equipped.Value)
				end
			end

			local number = tonumber(clone.Name)
			if number ~= 1 then
				local previousnum = number-1
				local itemfound = script.Parent:FindFirstChild(previousnum)
				if itemfound then
					if player.OwnedItems:FindFirstChild(itemfound.ToolName.Value) then
						clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(255,255,255) 
					end 
				end
			end
		end
		number = number+1
	until number == game.ReplicatedStorage.TotalTools.Value + 1
end)

Firstly, ClassName isn’t a method, it’s a property. You don’t use a colon.

image:ClassName("ImageLabel")

image.ClassName == "ImageLabel"

Secondly, I suppose if image is nil (attempt to index nil with ‘ClassName’) then you need to make sure that the ToolsImage thing has all the numbers you need. Perhaps make sure
game.ReplicatedStorage.ToolsImage:FindFirstChild(number)
converts the number to a string before checking? Like so: game.ReplicatedStorage.ToolsImage:FindFirstChild(tostring(number))

it still didn’t work i

i tried it but the same error

Can you show us your current script?

game.ReplicatedStorage.Remotes.PlayerLoaded:FireServer()
print("PlayerLoaded")
local player = game.Players.LocalPlayer
local number = 1
game.ReplicatedStorage.Remotes.BeginArrangement.OnClientEvent:Connect(function()
	print("Got")
	repeat
		local image = game.ReplicatedStorage.ToolsImage:FindFirstChild(tostring(number))
		if image.ClassName == "ImageLabel" then
			print(image.Name)
			local clone = game.ReplicatedStorage.Template:Clone()
			clone.ToolImageDisp.ImageLabel.Image = image.Image
			clone.Name = image.Name
			clone.CostDisplay.Value = image.Cost.Value
			clone.ToolName.Value = image.ToolName.Value
			clone.Parent = script.Parent
			clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(0,0,0) 

			if clone.Name == "1" then
				local sidemenu = script.Parent.Parent
				sidemenu.tool_img.Image = image.Image
				sidemenu.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
				sidemenu.status.Text = "Equip"
				sidemenu.price.cost.Value = 0
				sidemenu.price.Text = "Cost : 0"
				sidemenu.name.Text = clone.ToolName.Value

			end

			if player.OwnedItems:FindFirstChild(clone.ToolName.Value) then
				clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(255,255,255)
			end

			local equipped = player:WaitForChild("Equipped")
			if equipped.Value~= nil then
				if clone.ToolName.Value == equipped.Value then
					script.Parent.tool_img.Image = image.Image
					script.Parent.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
					script.Parent.ststus.TextButton.Text = "Equipped"
					script.Parent.price.Cost.Value = clone.CostDisplay.Value
					script.Parent.price.Text = "Cost : "..script.Parent.price.cost.Value
					script.Parent.name.Text = clone.ToolName.Value
					game.ReplicatedStorage.Remotes.EquipTool:FireServer(equipped.Value)
				end
			end

			local number = tonumber(clone.Name)
			if number ~= 1 then
				local previousnum = number-1
				local itemfound = script.Parent:FindFirstChild(previousnum)
				if itemfound then
					if player.OwnedItems:FindFirstChild(itemfound.ToolName.Value) then
						clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(255,255,255) 
					end 
				end
			end
		end
		number = number+1
	until number == game.ReplicatedStorage.TotalTools.Value + 1
end)

Use

Image:IsA(“ImageLabel”)

I’m not sure what your trying to do but I think this will work.

Edit: when you do FindFirstChild() you need a string, not a number.

i tried it. But it didnt work
my script:


game.ReplicatedStorage.Remotes.PlayerLoaded:FireServer()
print("PlayerLoaded")
local player = game.Players.LocalPlayer
local number = 1
local strings = tostring(number)
game.ReplicatedStorage.Remotes.BeginArrangement.OnClientEvent:Connect(function()
	print("Got")
	repeat
		local image = game.ReplicatedStorage.ToolsImage:FindFirstChild(strings)
		if image:IsA("ImageLabel") then
			print(image.Name)
			local clone = game.ReplicatedStorage.Template:Clone()
			clone.ToolImageDisp.ImageLabel.Image = image.Image
			clone.Name = image.Name
			clone.CostDisplay.Value = image.Cost.Value
			clone.ToolName.Value = image.ToolName.Value
			clone.Parent = script.Parent
			clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(0,0,0) 

			if clone.Name == "1" then
				local sidemenu = script.Parent.Parent
				sidemenu.tool_img.Image = image.Image
				sidemenu.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
				sidemenu.status.Text = "Equip"
				sidemenu.price.cost.Value = 0
				sidemenu.price.Text = "Cost : 0"
				sidemenu.name.Text = clone.ToolName.Value

			end

			if player.OwnedItems:FindFirstChild(clone.ToolName.Value) then
				clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(255,255,255)
			end

			local equipped = player:WaitForChild("Equipped")
			if equipped.Value~= nil then
				if clone.ToolName.Value == equipped.Value then
					script.Parent.tool_img.Image = image.Image
					script.Parent.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
					script.Parent.ststus.TextButton.Text = "Equipped"
					script.Parent.price.Cost.Value = clone.CostDisplay.Value
					script.Parent.price.Text = "Cost : "..script.Parent.price.cost.Value
					script.Parent.name.Text = clone.ToolName.Value
					game.ReplicatedStorage.Remotes.EquipTool:FireServer(equipped.Value)
				end
			end

			local number = tonumber(clone.Name)
			if number ~= 1 then
				local previousnum = number-1
				local itemfound = script.Parent:FindFirstChild(previousnum)
				if itemfound then
					if player.OwnedItems:FindFirstChild(itemfound.ToolName.Value) then
						clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(255,255,255) 
					end 
				end
			end
		end
		number = number+1
	until number == game.ReplicatedStorage.TotalTools.Value + 1
end)

help (i appreciate it) thank you

change to

if image:IsA("ImageLabel") then

or

if image.ClassName == "ImageLabel" then

there is no :ClassName(class), only :IsA(class) or .ClassName

i changed it, it still didn’t work
my script:


game.ReplicatedStorage.Remotes.PlayerLoaded:FireServer()
print("PlayerLoaded")
local player = game.Players.LocalPlayer
local number = 1
local strings = tostring(number)
game.ReplicatedStorage.Remotes.BeginArrangement.OnClientEvent:Connect(function()
	print("Got")
	repeat
		local image = game.ReplicatedStorage.ToolsImage:FindFirstChild(strings)
		if image:IsA("ImageLabel") then
			print(image.Name)
			local clone = game.ReplicatedStorage.Template:Clone()
			clone.ToolImageDisp.ImageLabel.Image = image.Image
			clone.Name = image.Name
			clone.CostDisplay.Value = image.Cost.Value
			clone.ToolName.Value = image.ToolName.Value
			clone.Parent = script.Parent
			clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(0,0,0) 

			if clone.Name == "1" then
				local sidemenu = script.Parent.Parent
				sidemenu.tool_img.Image = image.Image
				sidemenu.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
				sidemenu.status.Text = "Equip"
				sidemenu.price.cost.Value = 0
				sidemenu.price.Text = "Cost : 0"
				sidemenu.name.Text = clone.ToolName.Value

			end

			if player.OwnedItems:FindFirstChild(clone.ToolName.Value) then
				clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(255,255,255)
			end

			local equipped = player:WaitForChild("Equipped")
			if equipped.Value~= nil then
				if clone.ToolName.Value == equipped.Value then
					script.Parent.tool_img.Image = image.Image
					script.Parent.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
					script.Parent.ststus.TextButton.Text = "Equipped"
					script.Parent.price.Cost.Value = clone.CostDisplay.Value
					script.Parent.price.Text = "Cost : "..script.Parent.price.cost.Value
					script.Parent.name.Text = clone.ToolName.Value
					game.ReplicatedStorage.Remotes.EquipTool:FireServer(equipped.Value)
				end
			end

			local number = tonumber(clone.Name)
			if number ~= 1 then
				local previousnum = number-1
				local itemfound = script.Parent:FindFirstChild(previousnum)
				if itemfound then
					if player.OwnedItems:FindFirstChild(itemfound.ToolName.Value) then
						clone.ToolImageDisp.ImageLabel.ImageColor3 = Color3.fromRGB(255,255,255) 
					end 
				end
			end
		end
		number = number+1
	until number == game.ReplicatedStorage.TotalTools.Value + 1
end)

you might wanna check if image is not returning nil.

by doing this:

local image = game:GetService("ReplicatedStorage").ToolsImage:FindFirstChild(strings) -- use GetService for services like replicatedstorage
if image == nil then return end

or you can do WaitForChild (i recommend doing waitforchild in your case since you need to use the image)

local image = game:GetService("ReplicatedStorage").ToolsImage:WaitForChild(strings)

after all, i heard it takes a little bit of time for something to replicate to the client

tysm it worked for me have a great day! :slight_smile: