You can write your topic however you want, but you need to answer these questions:
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
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
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
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 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.
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)
--//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
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)
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