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:
01 | function edit(h) |
02 | if h ~ = nil then |
03 | h.WalkSpeed = 25 |
04 | end |
05 | end |
06 |
07 | while true do |
08 | cur = game.Players:GetChildren() |
09 | for i = 1 , #cur do |
10 | edit(cur [ i ] .Character.Humanoid) |
11 | wait( 0.1 ) |
12 | end |
13 | wait( 4 ) |
14 | end |
Here is script from shop, maybe someone will need it too:
01 | local dialog = script.Parent |
02 |
03 | function answer(player, pick) |
04 | local char = player.Character |
05 | local humanoid = char [ "Humanoid" ] |
06 | local stats = player:findFirstChild( "leaderstats" ) |
07 | local g = stats:findFirstChild( "Points" ) |
08 | if pick.Name = = "30" then |
09 | if g.Value > = 500 then |
10 | humanoid.WalkSpeed = humanoid.WalkSpeed + 30 |
11 | g.Value = g.Value - 500 |
12 |
13 | end |
14 | end |
15 | end |
16 |
17 |
18 | dialog.DialogChoiceSelected:connect(answer) |
It's dialog shop.
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:
01 | function edit(h) |
02 | if h ~ = nil then |
03 | h.WalkSpeed = 25 |
04 | end |
05 | end |
06 |
07 | game.Players.PlayerAdded:connect( function (player) |
08 | player.CharacterAdded:connect( function (char) |
09 | edit(char:WaitForChild( "Humanoid" )) |
10 | end |
11 | end ) |
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.
So now, here's a fix with my method of doing it:
1 | game.Players.PlayerAdded:connect( function (Plr) |
2 | Plr.CharacterAdded:connect( function (Char) |
3 | Speed = 25 |
4 | Char:FindFirstChild( "Humanoid" ).WalkSpeed = 25 |
5 | end ) |
6 | 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:
01 | game.Players.PlayerAdded:connect( function (Plr) |
02 | Plr.CharacterAdded:connect( function (Char) |
03 | if not Plr:FindFirstChild( "Speed" ) then |
04 | local Speed = Instance.new( "NumberValue" ,Plr) |
05 | Speed.Name = "PlrSpeed" |
06 | Speed.Value = 25 |
07 | else |
08 | local Speed = Plr:FindFirstChild( "PlrSpeed" ) |
09 | end |
10 | Char:FindFirstChild( "Humanoid" ).WalkSpeed = Speed.Value |
11 | Char:FindFirstChild( "Humanoid" ).Changed:connect( function (Property) |
12 | if Property = "WalkSpeed" then |
13 | Speed.Value = Char:FindFirstChild( "Humanoid" ).WalkSpeed |
14 | end |
15 | end ) |
16 | end ) |
17 | 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