Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I change only one person's stats on leaderboard?

Asked by 3 years ago

I just started Lua five days ago and I did a little bit of research and I am making a difficulty chart obby. I am making my leaderboard for the obby which tells you which stage you are on and which difficulty you are on. When I tested my leaderboard out in the studio with two players, when one player stepped on the first checkpoint, the leaderboard updated for all players. Is there any way I can fix this? I will show my code down below. Help is very appreciated and thank you in advanced. :)

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
    if player then
        local folder = Instance.new("Folder")
        folder.Name = "leaderstats"
        folder.Parent = player
        local stage = Instance.new("IntValue")
        stage.Name = "Stage"
        stage.Parent = folder
        stage.Value = 0
        local DifficultyChart = Instance.new("StringValue")
        DifficultyChart.Name = "Level"
        DifficultyChart.Parent = folder
        DifficultyChart.Value = "None"
        local checkpoint1 = game.Workspace.Checkpoint1
        checkpoint1.Touched:Connect(function(hit)
            local humanoid = hit.Parent:FindFirstChild("Humanoid")
            if humanoid then
                stage.Value = 1
                DifficultyChart.Value = "Too EZ"

                local checkpoint2 = game.Workspace.Checkpoint2
                checkpoint2.Touched:Connect(function(hit)
                    local humanoid = hit.Parent:FindFirstChild("Humanoid")
                    if humanoid then
                        stage.Value = 2
                    end
                end)
            end
        end)
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Hello, you should use remote events. Dont put the touched event in the same script with leaderstats because the event contains PlayerAdded too and that means it will change for everybody. You should add to the leaderstats only new stats, gamepasses, data saves, etc, not other systems because there will appear bugs. I hope this makes sense, you should use local scripts for every stage part, and the local script will fire a script from serverscriptservice that contains a onServerEvent with an remote that changes the actual player`s stage to another stage level. I hope this works, if you got any questions feel free to ask me! I also added you from an account called ArchangelKingLegacy, accept me and i ll help you further, i m looking for motivated incomming developer to learn together :D Have a good day :D

0
Wow! That was a good explanation. I watched a tutorial on remote events by TheDevKing and I can see what you mean. I will try to implement what you told me into my code and I hope I can learn developing with you. Thank you so much for answering I really appreciate it! Have a good day :D FilipinoWrld 22 — 3y
0
I have tried doing what you told me to and it worked! Thank you so much! FilipinoWrld 22 — 3y
Ad

Answer this question