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

Why when I die, the walkspeed does not save?

Asked by 3 years ago

So I made a script saying if you have one coin, walkspeed is = 21

    local players = game.Players.LocalPlayer

    script.Parent.MouseButton1Click:Connect(function(Click)
        if players.leaderstats.Coins.Value >= 1 then
            players.leaderstats.Coins.Value = players.leaderstats.Coins.Value - 1

            players.Character.Humanoid.WalkSpeed = 21
        end
    end)

But it came to my attention that when you die, your walkspeed get reset. can you help me? (Keep in mind that I have more than one of these scripts, and each one costs more and makes you faster.)

0
Or, you could just disable the reset button TheB4dComputer 100 — 3y
0
that's not what he wanted WINDOWS10XPRO 438 — 3y
0
Why are you changing the WalkSpeed on the client? Do it on the server. Dovydas1118 1495 — 3y
0
So what are you saying? Sorry, I am sorta new to scripting. kickoff127 103 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

You could save the value of the walkspeed somewhere other than the script and have another script load the walkspeed. You could also go to extremes and use datastores to save their data even when they leave the game (Save the walkspeed value in the player, not the character).

Btw, even with the new improvements, this script wouldn't work because player.Character doesn't work in localscripts. Or, if this isn't a localscript, Game.Players.LocalPlayer only works in localscripts. I Hope this helps!

0
So what are you saying? Sorry, I am sorta new to scripting. kickoff127 103 — 3y
Ad
Log in to vote
1
Answered by 3 years ago


game.Players.PlayerAdded:Connect(function(player) player.CharacterAddded:Connect(function(character) script.Parent.MouseButton1Click:Connect(function() if player.leaderstats.Coins.Value >= 1 then player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1 walkspeedbeforedeath = 21 character.Humanoid.WalkSpeed = walkspeed end end) end) end) game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:WaitForChild("Humanoid"):Connect(function(character) character.Humanoid.WalkSpeed = walkspeedbeforedeath end) end)

again, idk if this works, but it's pretty much what I can help. If it doesn't work, please be more specific as you can and try searching it on google.

1
I don't like when people just paste scripts and expect OP to figure it out. Add comments at the very least. Dovydas1118 1495 — 3y
0
This would work. I'll explain it to you as best as I can. Line 1: Detectign when a player joins the game and defining the player that joined as "player" TheB4dComputer 100 — 2y
0
Line 2: Detecting when the player's character is created and loaded. Defines the character as "character" TheB4dComputer 100 — 2y
0
Line 3: Detecting when the script's parent is clicked. TheB4dComputer 100 — 2y
View all comments (7 more)
0
Line 4: Does this player have enough coins? TheB4dComputer 100 — 2y
0
Line 5: If it does, reduce the coin count by 1. TheB4dComputer 100 — 2y
0
Line 6: Saving the walkspeed in the script. TheB4dComputer 100 — 2y
0
Line 7:Giving the character the correct amount of walkspeed. TheB4dComputer 100 — 2y
0
Line 7 would fail as "walkspeed" isn't defined. Say "walkspeedbeforedeath" instead. TheB4dComputer 100 — 2y
0
I also don't think you would need the last 5 lines. Just replace line 2 with line 15 and it should work. TheB4dComputer 100 — 2y
0
Also line 2 has an extra d. TheB4dComputer 100 — 2y

Answer this question