You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Whenever I reach 30 “Coins”, a part will change color
What is the issue? Part doesn’t change color
What solutions have you tried so far? Tried putting the Part color changing section into a separate script
So I want to make it whenever I reach 30 Coins, Part would change color
Part is called ColoredPart if it helps
game.Players.PlayerAdded:Connect(function(player)
local Coins = Instance.new("IntValue", player)
Coins.Name = "Coins"
Coins.Parent = player
while wait(2) do
Coins.Value = Coins.Value + 5
end
if Coins.Value >= 30 then
game.Workspace.ColoredPart.BrickColor = BrickColor.new(0, 255, 0)
end
end)
Anyone might be able to figure out why? I don’t get any errors in output either.
I’m think you cant use BrickColor.new(0, 255, 0).
You only can use BrickColor.new(“Green”)
Or game.Workspace.ColoredPart.Color3 = Color3.new(0, 255, 0) – and you cant use 0, 255, 0. Use 0.0666667, 1, 0
Firstly you need to use ColoredPart.Color3 = Color3.fromRGB(0, 255, 0)
Secondly you need to wrap the loop in a coroutine like this:
coroutine.resume(coroutine.create(function()
while true do
task.wait(2)
Coins.Value += 5
end
end))
Edit: You need to wrap it in a coroutine so that the code after the loop runs
Another issue with the code is that it only checks if you have more than 30 coins once, instead you need to check it every time it updates:
Coins:GetPropertyChangedSignal("Value"):Connect(function()
if Coins.Value >= 30 then
game.Workspace.ColoredPart.Color3 = Color3.fromRGB(0, 255, 0)
end
end)