Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could I make this shorter?

Asked by 8 years ago
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?

0
Do you want explanation with the code I can provide? Or can you figure it out? M39a9am3R 3210 — 8y
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 NinjoOnline 1146 — 8y

1 answer

Log in to vote
2
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

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"
Ad

Answer this question