I’m attempting to make a part change colour every 2 seconds, then move up a bit after 10 seconds (while still changing colour) before moving back down to where it originally was.
The script is doing the first bit of it correctly, and changing the colour every 2 seconds. However, it is not doing the second part where it is meant to move up and down. I’ve had a look around the DevForum but I am still a bit unsure of what the error is.
Part = game.Workspace.Part
spawn(function()
local i = 0
while true do
i = i + wait()
wait(2)
Part.BrickColor = BrickColor.new("Cork")
wait(2)
Part.BrickColor = BrickColor.new("Medium blue")
if i >=10 then
i = 0
Part.Position = Vector3(0.51,5,-14.55)
wait(10)
Part.Position = Vector3(0.51,0.5,-14.55)
end
end
end)
You should be accumulating each wait, or just using a clock and figuring out the difference. The following would go wherever you want to ‘set’ the clock to zero:
local startTime = os.clock()
Then, when you want to know how much time has passed:
os.clock() - startTime
In your script, this would be:
Part = game.Workspace.Part
spawn(function()
local startTime = os.clock()
while true do
wait(2)
Part.BrickColor = BrickColor.new("Cork")
wait(2)
Part.BrickColor = BrickColor.new("Medium blue")
if os.clock() - startTime >= 10 then
startTime = os.clock()
Part.Position = Vector3.new(0.51,5,-14.55)
wait(10)
Part.Position = Vector3.new(0.51,0.5,-14.55)
end
end
end)
I’m unclear as to whether you want to reset the timer in it’s current place though. In the code above and your original example, you reset the clock then wait 10 seconds (which means it’ll run again the next time). If that’s not what you want, you should reset the clock after waiting 10 seconds.
Unsure if it’s a problem on my end, but that seems to change colour until it hits the part where it is meant to move up and down. When it’s meant to move up and down it freezes on blue, and sits stationary rather than moving up.