THIS LITTLE SCRIPT IS DRIVING ME CRAZY!!!
I’m Trying To Track the Player’s Height In LeaderStats. And I’m Trying To Increase The Players Speed (And Put It In LeaderStats) when The Player Gets To 500 studs, Then 1000, 1500, etc., But The Speed Won’t Work On The Player Until The Player’s Heath Gets to Zero. Here’s An Example:
game:GetService("Players").PlayerAdded:Connect(function(player)
local StarterPlayer = game.StarterPlayer
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Height = Instance.new("NumberValue")
Height.Name = "Height"
Height.Parent = leaderstats
local Speed = Instance.new("NumberValue")
Speed.Name = "Speed"
Speed.Parent = leaderstats
StarterPlayer.CharacterWalkSpeed = 16
Speed.Value = StarterPlayer.CharacterWalkSpeed
local character = player.CharacterAdded:Wait()
while task.wait() do
local TimesWon = 1
local TotalGoal = 0
TotalGoal = TimesWon * 500
Height.Value = character:GetPivot().Position.Y
if Height.Value >= TotalGoal then
TimesWon = TimesWon + 1
Speed.Value = Speed.Value + 2
task.wait(0.1)
StarterPlayer.CharacterWalkSpeed = StarterPlayer.CharacterWalkSpeed + 2
end
end
end)
local players = game:GetService('Players')
local TimesWon = 1
local TotalGoal = 0
function PlayerAdded(player)
--/ Player joined the game
local function CharacterAdded(character)
--/ Player spawned
while task.wait() do
(TotalGoal + 1) *= 500
player.leaderstats.Height.Value = character:GetPivot().Position.Y
if player.leaderstats.Height.Value >= TotalGoal then
TimesWon += 1
player.leaderstats.Speed.Value += 2
wait()
player.Character:WaitForChild('Humanoid').WalkSpeed += 2
end
end
end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Height = Instance.new("NumberValue")
Height.Name = "Height"
Height.Parent = leaderstats
local Speed = Instance.new("NumberValue")
Speed.Name = "Speed"
Speed.Parent = leaderstats
Speed.Value = 16
player.Character:WaitForChild('Humanoid').WalkSpeed = 16
players.PlayerAdded:Connect(CharacterAdded)
end
You forgot to define TimesWon (Would recommend inside of the characterAdded function)
Edit: You defined it, but you should probably put it inside of the CharacterAdded function, leaving it outside of even the PlayerAdded function would make it replicate across all players.
I declared it at the top outside of the function but because i do not know all the details of his system i cannot safely put it anywhere i would need to know more to get a real solution
For example i do not know if timeswon is supposed to be a serverwide thing or a player thing
If it is a player thing then i suggest to make it a leaderstat
Well, there are a few problems with his script; he never connected the PlayerAdded function to a PlayerAdded event, he connected the CharacterAdded event to a PlayerAdded event, and he also made the TotalGoal infinitely increase. Here is a fixed version of his script.
local players = game:GetService('Players')
local TimesWon = 1
local TotalGoal = TotalWon * 500
function PlayerAdded(player)
--/ Player joined the game
local function CharacterAdded(character)
character:WaitForChild('Humanoid').WalkSpeed = 16
while task.wait() do
player.leaderstats.Height.Value = character:GetPivot().Position.Y
if player.leaderstats.Height.Value >= TotalGoal then
TimesWon += 1
player.leaderstats.Speed.Value += 2
TotalGoal = TotalWon * 500
character:WaitForChild('Humanoid').WalkSpeed += 2
end
end
end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Height = Instance.new("NumberValue")
Height.Name = "Height"
Height.Parent = leaderstats
local Speed = Instance.new("NumberValue")
Speed.Name = "Speed"
Speed.Parent = leaderstats
Speed.Value = 16
player.CharacterAdded:Connect(CharacterAdded)
end
players.PlayerAdded:Connect(PlayerAdded)