Saving walkspeed to variable

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    For the humanoid walkspeed to be saved to a variable like plrSpeed for example
  2. What is the issue? Include screenshots / videos if possible!
    So I have it saving I think, but it doesn’t change the value when increased or decreased
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried looking on the Web in places like the Hub and scriptinghelper, but I couldnt find any solutions related to the issue
1 Like

We don’t quite get your issue. Can you please describe it briefly?

If you’re trying to change the WalkSpeed by changing the plrSpeed variable, it won’t work because things like strings and numbers are immutable and when you save them to a variable, it saves the value of what the WalkSpeed is, not the reference to the WalkSpeed property.

local PlayerSpeed = 16

game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").WalkSpeed = PlayerSpeed

---

PlayerSpeed = game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").WalkSpeed

Maybe you should use an Attribute…

put this in a local script in …
image

local character = script.Parent

local humanoid = character:WaitForChild("Humanoid")

local plrSpeed = humanoid:SetAttribute("plrSpeed",humanoid.WalkSpeed)

--detect change

humanoid:GetAttributeChangedSignal("plrSpeed"):Connect(function()

--do something when the variable is changed

print("plrSpeed changed to ",humanoid:GetAttribute("plrSpeed"))

end)

wait(3)

--make a change

humanoid:SetAttribute("plrSpeed",32)

This might give you some insight into what you are wanting to do, hope it helps.

This should work!

game.Players.PlayerAdded:Connect(function(Player)
    local Data = Instance.new("Folder", Player)
    Data.Name = "Data"

    local WalkSpeed = Instance.new("NumberValue", Data)
    WalkSpeed.Name = "WalkSpeed"
    WalkSpeed.Value = DataStore:GetAsync("Player_"..Player.UserId) or 16

    Player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed = tonumber(WalkSpeed.Value)
end)

Player.PlayerRemoving:Connect(function(PlayerRemoved)
    local success, result = pcall(function()
        DataStore:SetAsync("Player_"..PlayerRemoved.UserId)
    end)

    if not success then
        error(result)
    end
end)

This will in fact, not work! But thanks for your additions!

How about I show my part of the code?, the showing the value and also the changing of it ?

Yes, please something XD the original post is rather vague.

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Button = script.Parent
local Humanoid = Players.LocalPlayer.Character:WaitForChild("Humanoid")

local hWalk = Humanoid.WalkSpeed
local Walk = LocalPlayer.plrSpeed

--//Functions
Button.MouseButton1Click:Connect(function()
	LocalPlayer.plrSpeed.Value += LocalPlayer.Character.Humanoid.WalkSpeed
	if LocalPlayer.Character.Humanoid.WalkSpeed < LocalPlayer.Agility.Value / 60 then
		LocalPlayer.plrSpeed.Value += 4
	end
end)

while wait(2) do
	Humanoid.WalkSpeed = LocalPlayer.plrSpeed.Value
	Humanoid.JumpPower = LocalPlayer.plrJump.Value
	print("Current walkspeed: ".. Humanoid.WalkSpeed)
	print("Current jumppower: ".. Humanoid.JumpPower)
end

^^ adding it

--//Services
local Players = game:GetService("Players")

--//Variables
local Humanoid = Players.LocalPlayer.Character:WaitForChild("Humanoid")
local TextLabel = script.Parent
local plr = Players.LocalPlayer

--//Functions
TextLabel.Text = "Speed: " ..Humanoid.WalkSpeed

Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
	TextLabel.Text = "Speed: " ..Humanoid.WalkSpeed
end)

^^ showing it

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Button = script.Parent

--//Functions
Button.MouseButton1Click:Connect(function()
	LocalPlayer.plrSpeed.Value -= 4 < 4
end)

^^removing it

its most likely a bit messy as was done at the back of 1am :confused:

It sometimes reverts back to the previous number, so if its at 55, and changed to 66, it then changes back to 55

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local PlayerWalkSpeed = Humanoid.WalkSpeed

Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
     PlayerWalkSpeed = Humanoid.WalkSpeed
end)

ill let you know how it goes thanks

You didn’t save the Walk Speed at PlayerRemoving, it just save nothing, so try
DataStore:SetAsync(“Player_ “…PlayerRemoved.UserId, PlayerRemoved.Character:FindFirstChildOfClass(“Humanoid”).WalkSpeed

i have a datastore for the players, and one for plrSpeed,. its just trying to get the walkspeed to then save as the plrSpeed

Oops, thanks for pointing that out!