my speed script won’t work!
it won’t increase my speed!
and it also won’t increase my leaderstats speed value!
script:
local player = game.Players:GetPlayers()
for i, v in pairs(player) do
if v.Character then
v.Character.Humanoid.Speed += 1
player.leaderstats.Speed.Value += 1
end
end
i tryed it but none of it increased my speed, my leaderstats script and my walk speed dint increased hm.
what i tryed:
local player = game.Players:GetPlayers()
for i, v in pairs(player) do
if v.Character then
v.Character.Humanoid.WalkSpeed += 1
player.leaderstats.Speed.Value += 1
end
end
I’m a little rusty on my Roblox Lua, so I apologize in advance. But you could try that, although you will have the leaderstat issue (must be server-sided), so you would need to fire a remote event in that case which isn’t the most secure thing for data (or so I’ve heard/believe).
Edit: you could do it the other way around for changing the Humanoid properties if that is the issue here. Although I would first see if anything pops up in the output console, so we can determine what the problem is.
I believe I know what your issue is. I did a quick test in Studio and found that the problem may be related to your variable or for loop.
Your character may not be completely loaded in yet, so if this is the only code in your script then it is running before it can establish a player. Meaning you need to find a way to hault your code, so players can load in.
Since this is server-sided, a better option might be to use the PlayerAdded built in event.
game.Players.PlayerAdded:Connect(function()
-- code here
end)
It is possible to put in either StarterPlayerScripts or StarterCharacterScripts, as a LocalScript, but once transformed into LocalScript, the code will change to detect a few things… Here is a little sample:
local Players = game:GetService(”Players”)
local player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
Players.PlayerAdded:Connect(function()
local Humanoid = Character:FindFirstChildOfClass(”Humanoid”)
if (Humanoid) then
Humanoid.WalkSpeed += 1
end
end)
game.ReplicatedStorage.Remotes.givespeed.OnServerEvent:Connect(function(player)
while wait(1) do
if player.Character then
player.Character.Humanoid.WalkSpeed += 1
player.leaderstats.Speed.Value += 1
end
end
end)
Glad you found a solution! For best practice I would try to use the PlayerAdded event and not have the client fire immediately to the server for stuff. I also would not add a wait() in the beginning of your code because that is also not a good practice.