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)
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