I have a level system in my game, What I am trying to achieve is that like when the player’s level increases ‘+1’; the walk speed should increase like ‘+5’ and this should keep going on.
I feel this could be achieved by doing something like base + (level-1)*increaseRate.
I am not much familiar with scripting so it’ll be awesome if someone could help me out with this or give me a sample script by which I could achieve this.
It is fairly simple. They want their walk speed to be BaseSpeed + CurrentLevel * Increment whenever CurrentLevel changes.
Also, for OP, if you can reach levels like 100, you would be going over 500 studs per second and you might want to make the speed logarithmic instead of linear (i.e. math.log(CurrentLevel * Increment)) or use another kind of formula like exponential (i.e. 0.5^CurrentLevel * (Increment/0.5))
Yeah, this is a much better way to do this. Is it possible if you could show me a sample script that I could refer to, as I ain’t able to get this right due to being pretty new to scripting?
All of the wiki pages i sent should have examples showing how to use each of them. You would just keep track of all the values for their levels and when it changes, update their character’s walkspeed if their character exists. Also, when they are spawned, you would change their new character’s walkspeed to reflect that current value as well.
Pseudocode (not lua so it is easier to learn / make yourself and understand the logic behind it)
compute = (currentLevel):
return Base + math.log(1 + currentLevel * Increment)
player.playeradded = (player):
local char
--add the value
value.changed = (new):
if char and char:find("Humanoid"):
char.Humanoid.walkspeed = compute(new - 1)
player.characteradded = (character):
char = character
character:waitfor("Humanoid").walkspeed = compute(value.Value - 1)
This should do for your problem.
You simply need to change the variables below, to your liking, and you need to change.
You may also need to change the leaderboard values, as I am not sure, how your leaderboard names are.
Hope this helps!
local speedcap = 50 -- If a player reaches this amount, they won't go faster.
local startspeed = 16 -- Put what the player should start with in speed.
local gainprlvl = 5 -- Set this to the increment.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
player.leaderstats.Level.Changed:Connect(function()
if char then
if char:FindFirstChild("Humanoid").WalkSpeed < speedcap then
char:FindFirstChild("Humanoid").WalkSpeed = startspeed + player.leaderstats.Level.Value * gainprlvl
else
char:FindFirstChild("Humanoid").WalkSpeed = speedcap
end
end
end)
end)
end)
line 7 should be player.leaderstats.Level.Changed:Connect(function() instead of player.leaderstats.Speed.Changed:Connect(function() otherwise it will only increase when speed changes which is not what he wanted…
Also @SimonA12345J your code would bind to Changed every time they respawn so they can actually lag the game and abuse memory by spamming respawn due to the massive amount of connections
@SimonA12345J’s code worked pretty well and I understood the logic on how it works, what happens with me is that I usually understand better from the actual script. Could you show a sample of using your method in Lua as well I am really curious about how that works too? Most importantly thanks for helping me out!
You could just try to make this script on your own because the Scripting Support category isn’t for asking for entire scripts (which is something that shouldn’t have been done in the OP - don’t ask for scripts in this category). Use the articles that have been given to you and attempt to make something out of those yourself.