Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[Solved] Why does my LocalScript not change the player's walk speed to the one defined?

Hello there! I have a thing where i want to set the player's WalkSpeed to the one defined in the leaderstats. Any help is appreciated, Thanks in advance!

LocalScript:

wait(5)
local players = game.Players
local plr = players.LocalPlayer
local plrName = plr.Name
local leaderstats = players:FindFirstChild(plrName).leaderstats
local h = game.Workspace:FindFirstChild(plrName).Humanoid

local VectorZero = Vector3.new(0, 0, 0)


local function Moved()		
	if h.MoveDirection ~= VectorZero then
		leaderstats.Speed = leaderstats.Speed + 1
	else
		print("Stopped Moving")
	end	
end


h:GetPropertyChangedSignal("MoveDirection"):Connect(Moved)

while true do
	wait()
	h.WalkSpeed = leaderstats.Speed / 10
end

Leaderboard script:

local function onPlayerJoin(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 0	
	cash.Parent = leaderstats
	
	local speed = Instance.new("IntValue")
	speed.Name = "Speed"
	speed.Value = 1
	speed.Parent = leaderstats	
end

game.Players.PlayerAdded:Connect(onPlayerJoin)


Explorer:

https://imgur.com/a/YCAs8Rv

Error:

22:52:07.425 - Players.EiOooAxea.PlayerScripts.LocalScript:24: attempt to perform arithmetic (div) on userdata and number

2 comments

0

Can you put your code into code blocks

0

yea sorry idk what happened it didnt put them

1 answer

✓ Accepted answer

You forgot .Value

So your code should be :

wait(5) local players = game.Players local plr = players.LocalPlayer local plrName = plr.Name local leaderstats = players:FindFirstChild(plrName).leaderstats local h = game.Workspace:FindFirstChild(plrName).Humanoid

local VectorZero = Vector3.new(0, 0, 0)

local function Moved()
if h.MoveDirection ~= VectorZero then 
leaderstats.Speed.Value = leaderstats.Speed.Value + 1 
else 
print("Stopped Moving") end end

h:GetPropertyChangedSignal("MoveDirection"):Connect(Moved)

while true do wait() h.WalkSpeed = leaderstats.Speed.Value / 10 end

This discussion is preserved as it was. New answers, comments, and votes are closed.