How to fix my code error

Hello i have a game that if you gain points you gain speed but when you use the prestige button you lose your speed on that server
How i can fix this?
Here is my script
local players = game:GetService(“Players”)

local leaderstats = player:WaitForChild(“leaderstats”)
local points = leaderstats:WaitForChild(“Points”)
if points then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
while task.wait(0.5) do
humanoid.WalkSpeed = points.Value / 3.14

1 Like

Are you using a Prestige Value at all within your leaderstats? Cause if you’re just only removing it’s speed, then you could probably do something like multiply the Prestige along with the Points to get the total Speed you want

Hi let me explain i have a speed simulator with 2 in game cureency points and prestige if you run your get points to get prestige you need lost all your points Minimum points to use the button is 25000 when you prestige you lose all you points and get 1 prestige and this refresh ppl character

Why not just create a RemoteEvent then which will detect the button input from the client, onto the server to properly check if the Player has reached over 25,000 points to increase +1 of their Prestige? You can use FireServer() on the client, and detect the event with OnServerEvent to check when it gets fired by a Player

-- Client Side
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Button = script.Parent

local function Clicked()

-- Server Side 
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local PointRequirement = 25000

    local leaderstats = Player:WaitForChild("leaderstats")
    local Points = leaderstats:WaitForChild("Points")
    local Prestige = leaderstats:WaitForChild("Prestige")

    if Points >= PointRequirement then
        Points.Value = 0
        Prestige.Value += 1

Also, your PlayerAdded Event will only fire once because it’s not detecting for every Character that’s being added inside the workspace (Even though you’re using a CharacterAdded Event, you’re not connecting it to a function but instead yielding for it), use a CharacterAdded function as well:

local Players = game:GetService("Players")

    local leaderstats = Player:WaitForChild("leaderstats")
    local Points = leaderstats:WaitForChild("Points")

        local Humanoid = Character:WaitForChild("Humanoid")

        Humanoid.WalkSpeed = (Points.Value / 3.14) -- * Prestige.Value (Your personal choice) 

Thanks but i already use a remote event for my prestige button

Hang on, whats the actual issue here?

When the player use prestige button and it load character BOOOM the loop stop and player get default speed