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

Need help with this GUI code, please?

Asked by
Xl5Xl5 65
8 years ago

Right so, I have this code where the image changes every 3 seconds to the next one in the frame table, however I want the "while wait" time to decrease for each kill better explaination in the code comments.

I am also wondering if someone can explain what these parts mean

local i = 1 
i = i + 1
    if i > #frames then
        i = 1
frames = {292939446,292939514,292939573,292939640,292939710,292939774,292939822,292939859,292939915,292939963,292939995}

kill = game.Players.LocalPlayer.leaderstats.Kills --- My leaderboard stat

decal = script.Parent 
local i = 1

-- Here I want to know depending how many kills the player has the faster the "decals" or images changes
-- Like for example; 3 seconds = 0 Kills, 2.8 = 1 Kills while the images "while wait" time decreases

while wait(3) do --- I know that the "while wait" 3 seconds is the wait time between the images
    decal.Image = 'rbxassetid://'..frames[i]
    i = i + 1
    if i > #frames then
        i = 1
    else
    end
end

Please help! many thanks!

1 answer

Log in to vote
0
Answered by 8 years ago

Well, if you put the wait time in a variable, and use the variable instead of the 3, it should work.

frames = {292939446,292939514,292939573,292939640,292939710,292939774,292939822,292939859,292939915,292939963,292939995}

kill = game.Players.LocalPlayer.leaderstats.Kills --- My leaderboard stat

decal = script.Parent 


-- Here I want to know depending how many kills the player has the faster the "decals" or images changes
-- Like for example; 3 seconds = 0 Kills, 2.8 = 1 Kills while the images "while wait" time decreases

local i = 1
local FrameSpeed = 3 -- Default to 3.
while wait(FrameSpeed) do --- I know that the "while wait" 3 seconds is the wait time between the images
    decal.Image = 'rbxassetid://'..frames[i]
    i = i + 1
    if i > #frames then
        i = 1
    end
    FrameSpeed = 3 - 0.2 * kill.Value -- This will remove 0.2 from the delay for every kill.
end

Since you're wondering what this does:

local i = 1 
i = i + 1
    if i > #frames then
        i = 1

The first line sets i to 1. The second line increments the value of i by one. The third and fourth lines check to see if i is bigger than the number of frames, and if so, resets i to 1.

0
Thanks! :D I always wondered what the i was xD Xl5Xl5 65 — 8y
Ad

Answer this question