local MouseEvent
local ServerTG
function SetPaint()
for i, child in pairs(PaintBG.ScrollingFrame:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end end
for i, color in pairs(game.ReplicatedStorage:WaitForChild("HouseSystem").Colors:GetChildren()) do
local ColorSelectClone = script.ColorSelect:Clone()
ColorSelectClone.Parent = PaintBG.ScrollingFrame
ColorSelectClone.BackgroundColor3 = color.Value.Color
MouseEvent = ColorSelectClone.MouseButton1Click:Connect(function()
MouseEvent:Disconnect()
PaintBG.ColorPreview.BackgroundColor3 = color.Value.Color PaintBG.ColorName.Text = tostring(color.Value.Name)
for i, colorpart in pairs(game.Players.LocalPlayer.PlayerHouseInfoFolder.ActualHouse.Value.Main:GetChildren()) do
colorpart.BrickColor = color.Value
end
end)
end
ServerTG = PaintBG.Confirm.MouseButton1Click:Connect(function()
ServerTG:Disconnect()
print(PaintBG.ColorName.Text)
end)
end
while wait(1) do
--UpdateInventorySelect()
SetPaint()
end
Could someone please point out what’s wrong with my script?
Its because you call setpaint in a while loop that iterates ever second. And in that function you make connections to an event. So each second a new connection is being made meaning the same function will run multiple times on one event fire
Fix would be you disconnect both events in first lines of SetPaint() where right now you disconnect them when the connected event fires
I always thought the best solution to keep a ui up to date was to use “while” to always update every second.
But still calling SetPaint() just once, the colors don’t show up in the UI.
Wait a minute i just realized the other mistake you made. You are connecting different events using the same variable. So when MouseClick is assigned to a new connection, you wont have access to the connection you replaced. Its never disconnected
To fix just do local MoveClick = connection. That way you create a new variable each time which will be the one being referenced in the function
I just found another solution
I remove setpaint(), now the lines are free in the script and it seems that it worked, I’m using as a reference to change the color of the player’s house in the client, the name of the color in question which is in: “PaintBG.ColorName.Text”
local ServerTG
function SetPaint()
for i, child in pairs(PaintBG.ScrollingFrame:GetChildren()) do
if child:IsA("TextButton") then child:Destroy() end end
for i, color in pairs(game.ReplicatedStorage:WaitForChild("HouseSystem").Colors:GetChildren()) do
local ColorSelectClone = script.ColorSelect:Clone()
ColorSelectClone.Parent = PaintBG.ScrollingFrame
ColorSelectClone.BackgroundColor3 = color.Value.Color
local MouseEvent = ColorSelectClone.MouseButton1Click:Connect(function()
MouseEvent:Disconnect()
PaintBG.ColorPreview.BackgroundColor3 = color.Value.Color PaintBG.ColorName.Text = tostring(color.Value.Name)
for i, colorpart in pairs(game.Players.LocalPlayer.PlayerHouseInfoFolder.ActualHouse.Value.Main:GetChildren()) do
colorpart.BrickColor = color.Value
end
end)
end
ServerTG:Disconnect()
ServerTG = PaintBG.Confirm.MouseButton1Click:Connect(function()
ServerTG:Disconnect()
print(PaintBG.ColorName.Text)
end)
end
Mk finished. Didnt mean to delete the while loop so keep that in there. If you need to use it like that then go for it. Only thing is you gotta be careful when connecting events. Cuz if not checked you could have thousands of connections causing alot of lag