Hello i created a speed simulator but some servers have a issue and players get default speed how i can fix this
Speed Script (Server) :
while wait(.5) do
local children = game.Players:GetChildren()
for i = 1 , #children do
if children [i].Character ~= nil then
local hum = children [i].Character.Humanoid
hum.WalkSpeed = children [i].leaderstats.Points.Value / 3.12 + 1
end
end
end
Leaderstats Script (Server):
PointData = game:GetService("DataStoreService"):GetDataStore("PointData")
PrestigeData = game:GetService("DataStoreService"):GetDataStore("PrestigeData")
game.Players.PlayerAdded:Connect(function(plr)
local LB = Instance.new("IntValue")
LB.Name = "leaderstats"
local p = Instance.new("IntValue")
p.Name = "Points"
p.Value = PointData:GetAsync(plr.userId) or 0
local r = Instance.new("IntValue")
r.Name = "Prestige"
r.Value = PrestigeData:GetAsync(plr.userId) or 0
LB.Parent = plr
p.Parent = LB
r.Parent = LB
end)
game.Players.PlayerRemoving:Connect(function(plr)
PointData:SetAsync(plr.userId, plr.leaderstats.Points.Value)
PrestigeData:SetAsync(plr.userId, plr.leaderstats.Prestige.Value)
end)
Race condition where your while loop is running before leaderstats gets created. You shouldnât assume things exist when you try to index them, especially if theyâre dynamically created and not present right away when the server starts up.
Please put down a WaitForChild() before it checks for leaderstats, it assumes itâs there when it clearly isnât. something like âchildren[i]:WaitForChild(âleaderstatsâ)â should suffice.
local players = game:GetService("Players")
while task.wait(0.5) do
for _, player in ipairs(players:GetPlayers()) do
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local points = leaderstats:FindFirstChild("Points")
if points then
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = points.Value / 3.14
end
end
end
end
local DSS = game:GetService("DataStoreService")
local PointData = DSS:GetDataStore("PointData")
local PrestigeData = DSS:GetDataStore("PrestigeData")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local LB = Instance.new("Folder")
LB.Name = "leaderstats"
LB.Parent = plr
local p = Instance.new("IntValue")
p.Name = "Points"
p.Value = PointData:GetAsync(plr.userId) or 0
p.Parent = LB
local r = Instance.new("IntValue")
r.Name = "Prestige"
r.Value = PrestigeData:GetAsync(plr.userId) or 0
r.Parent = LB
end)
Players.PlayerRemoving:Connect(function(plr)
PointData:SetAsync(plr.userId, plr.leaderstats.Points.Value)
PrestigeData:SetAsync(plr.userId, plr.leaderstats.Prestige.Value)
end)
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local points = leaderstats:WaitForChild("Points")
if points then
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
task.spawn(function()
while task.wait(0.5) do
humanoid.WalkSpeed = points.Value / 3.14
end
end)
end
end)
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local points = leaderstats:WaitForChild("Points")
if points then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
task.spawn(function()
while task.wait(0.5) do
humanoid.WalkSpeed = points.Value / 3.14
end
end)
end
end)