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

When player dies their speed boost ends?

Asked by 2 years ago
Edited 2 years ago

I have a dev product that temporarily gives you a speed boost. My problem is that when you die your speed goes back to normal. How can I fix this? Heres the if statement for the devproduct:

   if receiptInfo.ProductId == 1289737124 then
            print("player bought 30sec speed boost")
            player.Character.Humanoid.WalkSpeed = 40
            for i = 30, 1, -1 do -- sets 30 second timer
                gui.Text = tostring(i)
                wait(1)
            end
            player.Character.Humanoid.WalkSpeed = 16
        end
0
Where is script located? Can you try putting it inside starterplayerscripts? it might work because it does not reset upon respawn Sabailuridze 126 — 2y
0
This is in ServerScriptStorage. Is it possible to put it in StarterPlayerScripts when its handling dev products? Sxribbly 16 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

A simple way to fix this would be to update the player's walkspeed every time the loop ticks as so:

if receiptInfo.ProductId == 1289737124 then
         print("player bought 30sec speed boost")
         player.Character.Humanoid.WalkSpeed = 40
         for i = 30, 1, -1 do -- sets 30 second timer
             gui.Text = tostring(I)
        player.Character.Humanoid.WalkSpeed = 40 --Update the speed every second
             wait(1)
         end
         player.Character.Humanoid.WalkSpeed = 16
     end

So if the player dies, their speed will still be boosted within a second

0
That's smart, cant believe I didn't think of that! It worked, thank you! Sxribbly 16 — 2y
0
No problem :) Rogue_Ram 40 — 2y
Ad

Answer this question