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

Changing WalkSpeed when Character respawned?

Asked by 2 years ago

I have been struggling with changing the walkspeed of a players humanoid upon them respawning after dying, i get no errors while testing - I am using RemoteEvent, i am not sure if that is neccesary

LocalScript is in the StarterCharacterScripts folder


-- LocalScript local plr = game.Players.LocalPlayer local char = script.Parent local hum = char:WaitForChild("Humanoid") local humroot = char:WaitForChild("HumanoidRootPart") local function onDeath() game.ReplicatedStorage.AddStats:FireServer() end hum.Died:Connect(onDeath) -- Script game.ReplicatedStorage.AddStats.OnServerEvent:Connect(function(plr) local char = plr.Character local hum = char:WaitForChild("Humanoid") local gui = plr.PlayerGui:WaitForChild("ValueGui") local textLabel = gui.JumpValue local walkSpeed = hum.WalkSpeed local jumpPower = hum.JumpPower print("Stats saved!") plr.CharacterAdded:Connect(function() print("character respawned") char:WaitForChild("Humanoid").WalkSpeed = walkSpeed hum.JumpPower = jumpPower end) end)

1 answer

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

Walking speed does not need Remote Events, you can use humanoid.WalkSpeed to change a humanoid's speed.

hum.WalkSpeed = 0

Edit: If you place a folder in a player with 2 intvalues that change their values as the humanoid changes its jumppower or walkspeed, then whenever a player respawns their character you can change their jumppower and walkspeed to those values. This will now only not work on the client side, so you have to change jumppower and walkspeed on the server side. If jumppower doesn't work, make sure your humanoids are using jumppower and not jumpheight.

Script creating two intvalues inside players as they join:

local Players = game:GetService("Players")

local StarterPlayer = game:GetService("StarterPlayer")

local function PlayerAdded(Player)

    local Folder = Instance.new("Folder")

    Folder.Name = "PlayerData"

    Folder.Parent = Player

    local IntValue1 = Instance.new("IntValue")

    IntValue1.Name = "JumpPower"

    IntValue1.Parent = Folder

    IntValue1.Value = StarterPlayer.CharacterJumpPower

    local IntValue2 = Instance.new("IntValue")

    IntValue2.Name = "WalkSpeed"

    IntValue2.Parent = Folder

    IntValue2.Value = StarterPlayer.CharacterWalkSpeed  

    local function CharacterAdded(Character)

        local Humanoid = Character:WaitForChild("Humanoid")

        Humanoid.JumpPower = IntValue1.Value

        Humanoid.WalkSpeed = IntValue2.Value

        local function JumpPowerChanged()

            IntValue1.Value = Humanoid.JumpPower
        end

        Humanoid:GetPropertyChangedSignal("JumpPower"):Connect(JumpPowerChanged)

        local function WalkSpeedChanged()

            IntValue2.Value = Humanoid.WalkSpeed
        end

        Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(WalkSpeedChanged)
    end

    Player.CharacterAdded:Connect(CharacterAdded)
end

Players.PlayerAdded:Connect(PlayerAdded)

Make sure to put this script in Game.ServerScriptService or Game.Workspace, as a server script of course.

Please let me know if my editing didn't help, I'll be happy to help.

0
My bad, i didnt describe it well enough. The idea of the game is that your walkspeed increases every few seconds and so does your JumpPower and i want to store the players speed and jump when they die so i can give them the exact amount of speed and jump they had before they died. luxen1711 9 — 2y
0
Thank you - I just tried it and it worked. I think the solution might just have been using GetPropertyChangedSignal. luxen1711 9 — 2y
1
I'm glad it worked. Would you please accept my answer if it helped? Then others don't have to respond anymore. Bankrovers 226 — 2y
Ad

Answer this question