So, I’m Trying to Make A Script That can Add Leaderstats, (But I Completed that Part) Multiply Numbers, and Changes The Player’s CharacterWalkSpeed.
Here’s an Example Code:
game:GetService("Players").PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Height = Instance.new("NumberValue")
Height.Name = "ExampleStat"
Height.Parent = leaderstats
local Player = player.CharacterAdded:Wait()
local StarterPlayer = game.StarterPlayer
local Cooldown = true
while true do --This Technically Updates The LeaderStats
local TimesWon = 1
local TotalGoal = --I'm Wanting To Multiply TimesWon With 500
wait()
Speed.Value = StarterPlayer.CharacterWalkSpeed
if Cooldown then
--Code to increase WalkSpeed
TimesWon = TimesWon + 1
end
end
end)
Could you please explain the problem further? What exactly is the issue? Do you get any errors?
From what I am guessing, you want to change the WalkSpeed based on times won (that is multiplied by 500?). If so, then you need to reference the player’s humanoid and change it there. Since you already have Player referenced (although I’d personally use local Player = player.Character or player.CharacterAdded:wait() instead), you can simply do local Humanoid = Player.Humanoid and then do something like Humanoid.WalkSpeed = TimesWon * 500.
One thing to note about the above is that the player wil be unable to move if TimesWon is 0, so it would be best to check if the value is greater than zero, otherwise have a default. This can be done with the following: Humanoid.WalkSpeed = if (TimesWon > 0) then TimesWon * 500 else 16
Lastly, there are some other questions. First of all, why are you running this in a while true loop? That seems unnecessary, so unless you have a specific reason, I highly recommend you have it linked with some type of event instead. Also, since everything is in a loop, TimesWon will keep getting reset back to 1 each iteration. Make sure to take it out of the loop if you do not want it to be reset.
Make the TotalGoal variable at the part in the script where you increase TimesWon by 1. Set it to 500 which is what you wanted to multiply times won by. Here is an example. local MultiplicationResult = TimesWon * TotalGoal