This is the script in the checkpoints.
local r = workspace:WaitForChild("RemoteEvent2")
function ot(hit)
if hit.Parent ~= nil then
local player = game.Players:playerFromCharacter(hit.Parent)
if player ~= nil then
if player.leaderstats.Stage.Value == script.Parent.Name - 1 then
script.Parent.Touched:Connect(function(hit)
print(player.leaderstats.Stage.Value)
if player.leaderstats.Stage.Value == script.Parent.Name - 1 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 15
local value = player.leaderstats.Coins.Value
print(value)
r:FireClient(player, value) -- This is to update a gui with coins.
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if h.Health ~= 0 then
player.leaderstats.Stage.Value = script.Parent.Name
print("fully done")
end
end
end
end)
end
end
end
end
Leaderboard script
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local r = Instance.new("RemoteEvent", workspace)
game.Players.PlayerAdded:Connect(function(player)
local char = player.Character or player.CharacterAdded:wait()
local ack = Instance.new("IntValue")
ack.Name = "leaderstats"
local ack2 = Instance.new("IntValue")
ack2.Name = "Stage"
ack2.Value = 1
ack2.Parent = ack
ack.Parent = player
local ls = player.leaderstats
ls:WaitForChild("Stage").Value = 1
local ack3 = Instance.new("IntValue", ack)
ack3.Name = "Prestige"
ack3.Value = 0
local Folder = Instance.new("Folder", player)
local ack4 = Instance.new("IntValue", player)
ack4.Name = "Skips"
ack4.Value = 0
local ack5 = Instance.new("IntValue", ack)
ack5.Name = "Coins"
ack5.Value = 0
local char = player.Character or player.CharacterAdded:wait()
local sl = game.Workspace:WaitForChild(ls.Stage.Value)
print(ls.Stage.Value)
local data
local data2
local data3
print(ls.Stage.Value)
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId .. "-Stage")
data2 = myDataStore:GetAsync(player.UserId .. "-Prestige")
data3 = myDataStore:GetAsync(player.UserId .. "-Coins")
print(ls.Stage.Value)
end)
if success then
if data ~= nil then
print(data)
ack2.Value = data
ack5.Value = data3
if char:WaitForChild("HumanoidRootPart") then
print("1")
local sl = game.Workspace:WaitForChild(ls.Stage.Value)
char:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,20,0)
print(sl)
end
else
local sl = game.Workspace:WaitForChild(ls.Stage.Value)
end
local char = player.Character or player.CharacterAdded:wait()
if char:WaitForChild("HumanoidRootPart") then
local sl = game.Workspace:WaitForChild(ls.Stage.Value)
char:WaitForChild("HumanoidRootPart").CFrame = char:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(0,20,0)
char:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,20,0)
print(sl)
print(sl.Position)
end
ack3.Value = data2
else
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
local char = player.Character or player.CharacterAdded:wait()
if char:WaitForChild("HumanoidRootPart") then
char:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,20,0)
warn(errormessage)
end
end
workspace.ChildAdded:Connect(function(obj)
if obj.Name == player.Name then
if obj:WaitForChild("HumanoidRootPart") then
local value = player.leaderstats.Coins.Value
r:FireClient(player, value)
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
obj:WaitForChild("HumanoidRootPart").CFrame = obj:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(0,20,0)
print(sl.CFrame)
end
wait()
if obj:WaitForChild("HumanoidRootPart") then
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
obj:WaitForChild("HumanoidRootPart").CFrame = sl.CFrame + Vector3.new(0,20,0)
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId .. "-Stage", player.leaderstats.Stage.Value)
myDataStore:SetAsync(player.UserId .. "-Prestige", player.leaderstats.Prestige.Value)
end)
if success then
print("Data Saved!")
else
warn(errormessage)
end
end)
This is the leader board script but I don't think the problems is here.
The scripts worked fine until there were 7 people in my game. When someone stepped on a checkpoint the stages of a group of people became the same (not everyone) and they got more coins than they were supposed to. I'm not sure if its just bad code or because those players (maybe) had data stored or because I used console commands to change certain player's stages back to 1 or there is a scripting mistake in a specific checkpoint. If you can see any problems with my script please let me know.
I've just done a test in studio with 6 players and I could not replicate the issue.
