Question, THIS IS DRIVING ME CRAZY! (Sorry, Not A Question)

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)

SO PLEASE, MOST ANSWERS HELP.

Because your setting starterplayer walkspeed, Instead do

 player.Character.Humanoid.WalkSpeed = 16

It only sets the walkspeed when the player dies because you are setting the starter player walkspeed instead of the current player walkspeed

Also do what @Kaid3n22 said

Move the TimesWon outside of the while loop.

Edit: As well as what @nexos_x7 said.

Sorry, I forgot to tell you, It’s a Script Some call it a Serverscript (Not A LocalScript)

Dosent matter just do what me and @Kaid3n22 said and it will work

The player was already defined from the PlayerAdded function.

Sorry @nexos_x7 and @Kaid3n22, Not working

You did have it looking like this, correct?

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()
	local TimesWon = 1

	while task.wait() do
		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)
			plr.Character.Humanoid.WalkSpeed += 2
		end
	end
end)

@nexos_x7’s new solution will provide an answer to after dying as well.

Use this

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

I rewrote it

1 Like

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

1 Like

Alright, I can understand that. But, one other problem I noticed is this:

Multiplying it by five hundred would still leave it at zero, causing people to always win.

Edit: The new solution would cause it to infinitely multiply, you should stick with OP’s original here.

Fixed, forgot about that little piece, but its kinda hard to build any real solution script without knowing more

By the way @ScenicDev and @Kaid3n22, LeaderStats Isn’t showing any thing

Screen Shot 2022-11-05 at 9.13.05 PM

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)
1 Like

Yea do what he said, Sorry for the scripting problems its late and ive been scripting all day Lol

To: @nexos_x7 You Don’t have to apologize, and I’m Tired Too. Lol


To: @Kaid3n22 Thank You, I’ve been Struggling for days. Lol

If you need any more help just msg me I can pretty much do anything
(not tonight though Lol)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.