For example if I have a stat named Speed being displayed on the leaderstats, how can i make a script to check it and depending on what value it is, it will add walkspeed to the character. For example at level 1, you get no extra speed, just regular 16, and when you increase a level it multiples is by 0.5 and add itself to become 24
how to change walkspeed based on leaderboard stat???
2 answers
First, make sure you're using a LocalScript. You would need to index the instances we're working with such as:
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local leaderstats = player:WaitForChild("leaderstats")
local walkSpeedStat = leaderstats:WaitForChild("Speed")
local levelStat = leaderstats:WaitForChild("Level").Value
local humanoid = character:FindFirstChild("Humanoid")
local walkSpeed = humanoid.WalkSpeed
From here we set up a .Changed statement that's intended to fire once levelStat is greater than it was before:
local currentLevel = levelStat --// allows us to keep track of each *level up*
levelStat.Changed:Connect(function()
if (levelStat > currentLevel) then --// Check if you leveled up
currentLevel = levelStat --// Updates tracker
if (humanoid) then
walkSpeed = (walkSpeed * .5 + walkSpeed) --// Upgrade walkSpeed
end
elseif (levelStat < currentLevel) then
if (humanoid) then
local difference = math.floor(currentLevel - levelStat)
walkSpeed = difference
currentLevel = (levelStat - 1)
end
end
if (currentLevel < 0 or levelStat < 1) then
levelStat = 1; currentLevel = 0
walkSpeed = 16
end
end)
Put it all together and you get:
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local leaderstats = player:WaitForChild("leaderstats")
local walkSpeedStat = leaderstats:WaitForChild("Speed")
local levelStat = leaderstats:WaitForChild("Level").Value
local humanoid = character:FindFirstChild("Humanoid")
local walkSpeed = humanoid.WalkSpeed
local currentLevel = levelStat
levelStat.Changed:Connect(function()
if (levelStat > currentLevel) then
currentLevel = levelStat
if (humanoid) then
walkSpeed = (walkSpeed * .5 + walkSpeed)
end
elseif (levelStat < currentLevel) then
if (humanoid) then
local difference = math.floor(currentLevel - levelStat)
walkSpeed = difference
currentLevel = (levelStat - 1)
end
end
if (currentLevel < 0 or levelStat < 1) then
levelStat = 1; currentLevel = 0
walkSpeed = 16
end
end)
Hope this helps
12 comments
I know this is a bit bland, if you need me to explain anything better, just ask
Are you from C++ or Java or some language that does //
Java, I don't do much framework anymore, but I know a bit of C++
i hate it when I post answers and the asker just stays idle and says nothing..
Jesus Christ my man your answer is way better than mine lol
Hey, at least you tried, you had a way better idea faster than I did, I took some time to think, It's New Years anyway, a bit tired too;)
If this Answer helped you press the Accept Answer button, help me help you?:)
Yeah hopefully he does because this answer is everything he needs
Thanks:) I upvoted you anyway, Happy new Year!
Oh jeez I fell asleep while on the job, laptop on my lap and all. Happy new Year to you as well my dude.
Sorry for the late reply but this helped also, thanks!
Happy to help
Ok so to do this, I'd first recommend making the first level 0, to make the script easier to handle. I was thinking of something along the lines of this
local Speed = player.Character.Humanoid.WalkSpeed
player.Character.Humanoid.WalkSpeed = Speed+Speed*0.5
Hopefully this answered your question and if it does not work, please say so and I will see if I did something wrong. Also copying and pasting what I wrote down as an example probably will not work, which is intentional because I do not want to give away free scripts.
3 comments
That's the point of all this, also it will not work, because it will only happen once, and won't add according to each level up
Instead of adding 0.5 of the original speed you could just multiply by 1.5. Just telling you to make your script simpler.
Thank you. I am a beginner at scripting so I will definitely learn from this :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
This is not a request site sorry :/
Eveyone requests for help, so do you, just help them, would you rather get is comment or something plausible?
thanks for all the help guys! I finally got it to work thanks to you!