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 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)
In the LocalScript, you can put this, it is way shorter and it works.
local player = script.Parent
player.Humanoid.WalkSpeed = 16
-- ^ Change this to the walking speed you want, 16 is the default
player.Humanoid.JumpPower = 50
-- ^ Change this to the jump power you want, 50 is the default
You don’t need to use RemoteEvents or server sided scripts to do this.
Hope this helped you.
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.
local defaultWalkSpeed = 16
local defaultJumpPower = 50
game.Players.PlayerAdded:Connect(function(plr)
local walkSpeedValue = Instance.new(“IntValue”)
walkSpeedValue.Name = “WalkSpeedValue”
walkSpeedValue.Value = defaultWalkSpeed
local jumpPowerValue = Instance.new(“IntValue”)
jumpPowerValue.Name = “JumpPowerValue”
jumpPowerValue.Value = defaultJumpPower
walkSpeedValue.Parent = plr
jumpPowerValue.Parent = plr
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild(“Humanoid”, 5)
if humanoid then
humanoid.WalkSpeed = walkSpeedValue.Value
humanoid.JumpPower = jumpPowerValue.Value
humanoid.Changed:Connect(function()
walkSpeedValue.Value = humanoid.WalkSpeed
jumpPowerValue.Value = humanoid.JumpPower
end)
end
end)
end)
I was unable to test this as I am on a phone, but it should work. If you want it to work specifically with JumpHeight instead of JumpPower, just go into the script editor and replace all instances of “JumpPower” with “JumpHeight”. Let me know if you get any errors.
I got help from another website and found the solution.
This is the script
local Players = game:GetService("Players")
local plr = game.Players.PlayerAdded:Wait()
local function CharacterAdded(Character) -- Character has respawned
print("character respawned")
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.JumpPower = plr.Values.JumpPower.Value -- Setting the JumpPower to the value of the IntValue
Humanoid.WalkSpeed = plr.Values.WalkSpeed.Value -- same here just with WalkSpeed
local function JumpPowerChanged()
plr.Values.JumpPower.Value = Humanoid.JumpPower -- Saving the JumpPower onto the Value everytime the player gets more JumpPower
end
local function WalkSpeedChanged()
plr.Values.WalkSpeed.Value = Humanoid.WalkSpeed -- same here just with WalkSpeed
end
Humanoid:GetPropertyChangedSignal("JumpPower"):Connect(JumpPowerChanged) -- Listening for changes to the JumpPower then running the function above ^
Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(WalkSpeedChanged)
end
plr.CharacterAdded:Connect(CharacterAdded)