Problem with my gui

Hey, Developers, i made a progress but i cant figure out whats wrong(im not that good at scripting), can someone tell me whats wrong? Thanks!



1 Like

The error means that you tried to mention a number value instead of an Instance.
Please provide your code so we can fix this.

3 Likes

Yes sure!

local Ducks = require(game.ReplicatedStorage:WaitForChild("DucksUIHandler"):WaitForChild("Ducks"))
local colors = {
	EASY = Color3.fromRGB(25,190,0),
	MEDIUM = Color3.fromRGB(255,170,0),
	HARD = Color3.fromRGB(170,10,10),
	MYTHICHAL = Color3.fromRGB(255,25,225),
	LIMITED = Color3.fromRGB(255,255,255),
	EXCLUSIVE = Color3.fromRGB(170,85,255),
}



for _, duck in ipairs(Ducks) do
	local slot = game.ReplicatedStorage.DucksUIHandler.Template:Clone()
	slot.Parent = script.Parent.Frame.Container
	slot.Name = duck.ID
	slot.ImageLabel.Image = "rbxthumb://type=Asset&id="..duck.imageID.."&w=420&h=420"
	slot.DifficultyLabel.Text = duck.difficulty
	slot.Namef.Text = duck.name
	slot.DifficultyLabel.BackgroundColor3 = colors[duck.difficulty]

	for slot, s in ipairs(game.Players.LocalPlayer.DucksFound:GetChildren()) do
		if s.Value == true then
			slot[s].BackgroundColor3 = Color3.new(0, 1, 0)
		else
			slot[s].BackgroundColor3 = Color3.new(1, 0, 0)
		end
	end
end


The error appears to be at this part of the code:

for slot, s in ipairs(game.Players.LocalPlayer.DucksFound:GetChildren()) do
		if s.Value == true then
			slot[s].BackgroundColor3 = Color3.new(0, 1, 0)
		else
			slot[s].BackgroundColor3 = Color3.new(1, 0, 0)
		end
	end
end

Slot is the index and s is the instance. Just do this:

for slot, s in ipairs(game.Players.LocalPlayer.DucksFound:GetChildren()) do
		if s.Value == true then
			s.BackgroundColor3 = Color3.new(0, 1, 0)
		else
			s.BackgroundColor3 = Color3.new(1, 0, 0)
		end
	end
end
3 Likes

From how it reads, I believe you are trying to use an Instance as a index against a number. Like when we get an element from our table with subscript operators ‘[ ]’.

Just saw your latest post. Check line 24. You are using slot as a table, but it is just a number value.

Thanks, but now the output gives me an error:

this is the other script:

It means that BackgroundColor3 is not a property or a child of the BoolValue you’re mentioning.

What are you trying to achieve?

1 Like

Okay so instead of changing the Background color of s, I believe if s.Value == true, you want to change the color of your gui element. Not s.

1 Like

im trying to make a gui that shows all the duck i collected so far by the red/green background.

im trying to make a gui that shows all the duck i collected so far by the red/green background, how do i do it?

local guiElementIWantToChange = player.PlayerGui.blahblah

if s.Value == true then
   guiElementIWantToChange.BackgroundColor3 = ColorYouWant
end

Then set the BackgroundColor3 property for the GUI, not the bool value. You can also check if the instance you’re currently iterating through is in a certain class or not:

if s:IsA("Frame") then -- if its a frame

end

ok, but there are multiple frames

You can still use the code I provided you. A for loop goes through all the instances in a table and gives you the instance and it’s index.

Okay so what you want to do is get these elements in a table. In your loop, you could use slots index to access your gui table and change it.

Provided the tables are parallel. So in the same order your duck badges are in, the gui table should be in.

The earlier code you provided will error because s is a boolean and doesn’t have a background3 property.

how do i do it, maybe if u can can u paste and edit my script in a reply? thanks!


image