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

How to fix walkspeed script?

Hello, I have problem with my walkspeed script when player join to game. So in my place i have something like a "speed shop", when player join to game script set his walkspeed on 25, but if player buy +30 walkspeed in speed shop it works only for a few seconds and set back 25 walkspeed... Here is walkspeed script:

function edit(h)
	if h ~= nil then
		h.WalkSpeed = 25
	end
end

while true do
	cur = game.Players:GetChildren()
	for i = 1, #cur do
		edit(cur[i].Character.Humanoid)
		wait(0.1)
	end
	wait(4)
end

Here is script from shop, maybe someone will need it too:

local dialog = script.Parent

function answer(player, pick)
	local char = player.Character
	local humanoid = char["Humanoid"]
	local stats = player:findFirstChild("leaderstats")
	local g = stats:findFirstChild("Points")
	if pick.Name == "30" then
		if g.Value >= 500 then
			humanoid.WalkSpeed = humanoid.WalkSpeed + 30
			g.Value = g.Value - 500
		
		end
	end
end


dialog.DialogChoiceSelected:connect(answer)

It's dialog shop.

2 answers

✓ Accepted answer

The problem is your WalkSpeed script every few seconds sets everyone's WalkSpeed to 25 - regardless of what speed they bought.

The easiest way to get around this is to only set the WalkSpeed to 25 when the Player's Character spawns:

function edit(h)
    if h ~= nil then
        h.WalkSpeed = 25
    end
end

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		edit(char:WaitForChild("Humanoid"))
	end
end)

1 comment

0

Thanks for help. Works perfectly.

##Problem The only problem is in your first script. You have the game constantly changing the WalkSpeed. To fix this, you need to only have the WalkSpeed be changed when the Player joins the game.


##Fix Fo' Da Script So now, here's a fix with my method of doing it:

game.Players.PlayerAdded:connect(function(Plr)
	Plr.CharacterAdded:connect(function(Char)
	Speed=25
	Char:FindFirstChild("Humanoid").WalkSpeed=25
	end)
end)

Now this would fix it so that it doesn't constantly mess up the WalkSpeed, but it wouldn't work when your player died. So to fix this, we'll add in this:

game.Players.PlayerAdded:connect(function(Plr)
	Plr.CharacterAdded:connect(function(Char)
		if not Plr:FindFirstChild("Speed") then
			local Speed=Instance.new("NumberValue",Plr)
			Speed.Name="PlrSpeed"
			Speed.Value=25
		else
			local Speed=Plr:FindFirstChild("PlrSpeed")
		end
		Char:FindFirstChild("Humanoid").WalkSpeed=Speed.Value
		Char:FindFirstChild("Humanoid").Changed:connect(function(Property)
			if Property="WalkSpeed" then
				Speed.Value=Char:FindFirstChild("Humanoid").WalkSpeed
			end
		end)
	end)
end)

Now this would work to keep the speed updated, even upon death.


Anyways, I hope this helped. If you have any further questions/problems, please leave a comment below, and I'll see what I can do :P

####-Dyler3

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