Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could I make this shorter?

for i = 3, 0, -1 do
	wait(1)
	if i == 3 then
		timeleft.Image = "rbxgameasset://Images/Respawn3"
	elseif i == 2 then
		timeleft.Image = "rbxgameasset://Images/Respawn2"
	elseif i == 1 then
		timeleft.Image = "rbxgameasset://Images/Respawn1"
	elseif i == 0 then
		timeleft.Image = "rbxgameasset://Images/RespawnNow"
	end
end

This whole script works and all, but I was just wondering is their an easier way to do this instead of constantly checking to see what i equals to?

2 comments

0

Do you want explanation with the code I can provide? Or can you figure it out?

0

An explanation would be nice, but I could probably also try and figure out, or if their is a wiki I could look up

1 answer

✓ Accepted answer

##Efficiency Fix

All I did was have a concatenation of the i value to the first three images. Then I moved the RespawnNow out of the for loop since the for loop terminates when it's done. Basically saying I just have the script automatically add the number to the end of the first three links, and then have the image change to RespawnNow when the for loop is done.


##Final Script

for i=3, 1, -1 do
    timeleft.Image = "rbxgameasset://Images/Respawn" .. tostring(i)
    wait(1)
end
timeleft.Image = "rbxgameasset://Images/RespawnNow"

This discussion is preserved as it was. New answers, comments, and votes are closed.