I have a section of my script (lines 55 to 57) which adds one to my deaths value every time the player dies but I think the event is firing too much as it goes up by like 50 to 600 deaths every time.
code:
local checkpoints = workspace.Checkpoints
local dss = game:GetService("DataStoreService")
local Datastore = dss:GetDataStore("ObbyData")
local Players = game:GetService("Players")
game:BindToClose(function()
for _,Player in pairs(Players:GetPlayers())do
Player:Kick("This server is shutting down")
end
wait(3)
end)
print("Checkpoints leaderstats working")
print("Deaths leaderstats working")
print("Time leaderstats working")
game.Players.PlayerAdded:Connect(function(plr)
local obbyData = Datastore:GetAsync(plr.UserId .. "-obbyStageProgress")
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local stage = Instance.new("StringValue")
stage.Name = "Stage"
stage.Value = (obbyData and obbyData[1]) or 1
stage.Parent = stats
local wipeouts = Instance.new("IntValue")
wipeouts.Name = "Deaths"
wipeouts.Value = 0
wipeouts.Parent = stats
local second = Instance.new("IntValue")
second.Name = "Seconds"
second.Value = 0
second.Parent = stats
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
char.Humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End"then
stage.Value = touch.Name
pcall(function()
Datastore:SetAsync(plr.UserId .. "-obbyStageProgress", {plr.leaderstats.Stage.Value, plr.Deaths.Value, plr.Seconds.Value})
end)
end
end
game.Players.PlayerRemoving:Connect(function(player)
Datastore:SetAsync(player.UserId,{player.leaderstats.Stage.Value, player.leaderstats.Deaths.Value,player.leaderstats.Seconds.Value} )
end)
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
hrp:GetPropertyChangedSignal("CFrame"):Wait()
hrp.CFrame = checkpoints[stage.Value].CFrame
humanoid.Died:Connect(function()
wipeouts.Value = wipeouts.Value + 1
end)
humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End" then
stage.Value = touch.Name
while wait(2)do
second.Value = second.Value + 1
end
pcall(function()
game.Players.PlayerRemoving:Connect(function(player)
Datastore:SetAsync(plr.UserId .. "-obbyStageProgress",{player.leaderstats.Stage.Value,player.leaderstats.Deaths.Value, player.leaderstats.Seconds.Value })
end)
end)
end
end
end)
end)
end)
end)
I tried the game but it still goes up by like 200 every time. If you need the full code here it is:
local checkpoints = workspace.Checkpoints
local dss = game:GetService("DataStoreService")
local Datastore = dss:GetDataStore("ObbyData")
local Players = game:GetService("Players")
game:BindToClose(function()
for _,Player in pairs(Players:GetPlayers())do
Player:Kick("This server is shutting down")
end
wait(3)
end)
print("Checkpoints leaderstats working")
print("Deaths leaderstats working")
print("Time leaderstats working")
game.Players.PlayerAdded:Connect(function(plr)
local obbyData = Datastore:GetAsync(plr.UserId .. "-obbyStageProgress")
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local stage = Instance.new("StringValue")
stage.Name = "Stage"
stage.Value = (obbyData and obbyData[1]) or 1
stage.Parent = stats
local wipeouts = Instance.new("IntValue")
wipeouts.Name = "Deaths"
wipeouts.Value = 0
wipeouts.Parent = stats
local second = Instance.new("IntValue")
second.Name = "Seconds"
second.Value = 0
second.Parent = stats
local wipeoutsData = Datastore:GetAsync(plr.UserId)
if wipeoutsData then
wipeouts.Value = wipeoutsData
end
local secondsData = Datastore:GetAsync(plr.UserId)
if secondsData then
second.Value = secondsData
end
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
char.Humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End"then
stage.Value = touch.Name
pcall(function()
Datastore:SetAsync(plr.UserId .. "-obbyStageProgress", {plr.leaderstats.Stage.Value, plr.Deaths.Value, plr.Seconds.Value})
end)
end
end
game.Players.PlayerRemoving:Connect(function(player)
Datastore:SetAsync(player.UserId,{player.leaderstats.Stage.Value, player.leaderstats.Deaths.Value,player.leaderstats.Seconds.Value} )
end)
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
hrp:GetPropertyChangedSignal("CFrame"):Wait()
hrp.CFrame = checkpoints[stage.Value].CFrame
local died = false
humanoid.Died:Connect(function()
if not died then
died = true
wipeouts.Value = wipeouts.Value + 1
wait(5)
died = false
end
end)
local humanoid = char:WaitForChild("Humanoid")
humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End" then
stage.Value = touch.Name
while wait(2)do
second.Value = second.Value + 1
end
pcall(function()
game.Players.PlayerRemoving:Connect(function(player)
Datastore:SetAsync(plr.UserId .. "-obbyStageProgress",{player.leaderstats.Stage.Value,player.leaderstats.Deaths.Value, player.leaderstats.Seconds.Value })
end)
end)
end
end
end)
end)
end)
end)
local died = false
local checkpoints = workspace.Checkpoints
local dss = game:GetService("DataStoreService")
local Datastore = dss:GetDataStore("ObbyData")
local Players = game:GetService("Players")
game:BindToClose(function()
for _,Player in pairs(Players:GetPlayers())do
Player:Kick("This server is shutting down")
end
wait(3)
end)
print("Checkpoints leaderstats working")
print("Deaths leaderstats working")
print("Time leaderstats working")
game.Players.PlayerAdded:Connect(function(plr)
local obbyData = Datastore:GetAsync(plr.UserId .. "-obbyStageProgress")
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local stage = Instance.new("StringValue")
stage.Name = "Stage"
stage.Value = (obbyData and obbyData[1]) or 1
stage.Parent = stats
local wipeouts = Instance.new("IntValue")
wipeouts.Name = "Deaths"
wipeouts.Value = 0
wipeouts.Parent = stats
local second = Instance.new("IntValue")
second.Name = "Seconds"
second.Value = 0
second.Parent = stats
local wipeoutsData = Datastore:GetAsync(plr.UserId)
if wipeoutsData then
wipeouts.Value = wipeoutsData
end
local secondsData = Datastore:GetAsync(plr.UserId)
if secondsData then
second.Value = secondsData
end
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
char.Humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End"then
stage.Value = touch.Name
pcall(function()
Datastore:SetAsync(plr.UserId .. "-obbyStageProgress", {plr.leaderstats.Stage.Value, plr.Deaths.Value, plr.Seconds.Value})
end)
end
end
game.Players.PlayerRemoving:Connect(function(player)
Datastore:SetAsync(player.UserId,{player.leaderstats.Stage.Value, player.leaderstats.Deaths.Value,player.leaderstats.Seconds.Value} )
end)
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
hrp:GetPropertyChangedSignal("CFrame"):Wait()
hrp.CFrame = checkpoints[stage.Value].CFrame
humanoid.Died:Connect(function()
if not died then
died = true
wipeouts.Value = wipeouts.Value + 1
wait(5)
died = false
end
end)
local humanoid = char:WaitForChild("Humanoid")
humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End" then
stage.Value = touch.Name
while wait(2)do
second.Value = second.Value + 1
end
pcall(function()
game.Players.PlayerRemoving:Connect(function(player)
Datastore:SetAsync(plr.UserId .. "-obbyStageProgress",{player.leaderstats.Stage.Value,player.leaderstats.Deaths.Value, player.leaderstats.Seconds.Value })
end)
end)
end
end
end)
end)
end)
end)