I am making a DCO, and I want to make a coin system, I want it so that when you touch a checkpoint, you gain a coin. Also I want it so that they can’t keep getting it by touching the same checkpoint again and again. I could invite you to my game (DudleySchoolLocks) or you can tell me here.
Thanks!
Regards, Alt_youlzr
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore(tostring(Configurations.DataSaveString))
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
game:GetService("RunService").Stepped:Wait()
wait(.5)
chr:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages[tostring(plr.TStage.Value)].CFrame + Vector3.new(0, 3.78, 0)
chr.Humanoid.Died:Connect(function()
chr:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages[tostring(plr.TStage.Value)].CFrame + Vector3.new(0, 3.78, 0)
end)
end)
end)
repeat wait() until game.ReplicatedStorage.Configurations ~= nil
local Configurations = require(game.ReplicatedStorage.Configurations)
for _, v in pairs(workspace.Stages:GetChildren()) do
v.Touched:Connect(function(hit)
if v and v.Parent == workspace.Stages then
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr then
if Configurations.AdvanceAliveOnly == true then
if plr.Character:WaitForChild("Humanoid").Health > 0 then
if plr.leaderstats.Stage.Value == tonumber(v.Name) - 1 then
plr.leaderstats.Stage.Value += 1
plr.TStage.Value = plr.leaderstats.Stage.Value
elseif plr.TStage.Value < tonumber(v.Name) - 1 then
plr.TStage.Value += 1
end
end
else
if plr.leaderstats.Stage.Value == tonumber(v.Name) - 1 then
plr.leaderstats.Stage.Value += 1
plr.TStage.Value = plr.leaderstats.Stage.Value
elseif plr.TStage.Value < tonumber(v.Name) - 1 then
plr.TStage.Value += 1
end
end
end
end
end)
end
game.ReplicatedStorage.ResetProgress.OnServerEvent:Connect(function(plr)
plr.leaderstats.Stage.Value = 0
plr.TStage.Value = 0
plr.Character:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages["0"].CFrame + Vector3.new(0, 3.78, 0)
game.ReplicatedStorage.ResetProgress:FireClient(plr)
local key = "ID_".. plr.UserId
local data = plr.leaderstats.Stage.Value
local success, error = pcall(function()
DS:SetAsync(key, data)
end)
if success then
print("Data saved: ".. key)
else
warn("Data ".. key.. " Unsuccessful when saving with error \"".. error.. "\"")
end
end)```
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore(tostring(Configurations.DataSaveString))
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
game:GetService("RunService").Stepped:Wait()
wait(.5)
chr:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages[tostring(plr.TStage.Value)].CFrame + Vector3.new(0, 3.78, 0)
chr.Humanoid.Died:Connect(function()
chr:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages[tostring(plr.TStage.Value)].CFrame + Vector3.new(0, 3.78, 0)
end)
end)
end)
repeat wait() until game.ReplicatedStorage.Configurations ~= nil
local Configurations = require(game.ReplicatedStorage.Configurations)
for _, v in pairs(workspace.Stages:GetChildren()) do
v.Touched:Connect(function(hit)
if v and v.Parent == workspace.Stages then
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr then
if Configurations.AdvanceAliveOnly == true then
if plr.Character:WaitForChild("Humanoid").Health > 0 then
if plr.leaderstats.Stage.Value == tonumber(v.Name) - 1 then
plr.leaderstats.Stage.Value += 1
plr.TStage.Value = plr.leaderstats.Stage.Value
elseif plr.TStage.Value < tonumber(v.Name) - 1 then
plr.TStage.Value += 1
end
end
else
if plr.leaderstats.Stage.Value == tonumber(v.Name) - 1 then
plr.leaderstats.Stage.Value += 1
plr.leaderstats.Stage.Value += AmountOfCoinsToGive
plr.TStage.Value = plr.leaderstats.Stage.Value
elseif plr.TStage.Value < tonumber(v.Name) - 1 then
plr.TStage.Value += 1
end
end
end
end
end)
end
game.ReplicatedStorage.ResetProgress.OnServerEvent:Connect(function(plr)
plr.leaderstats.Stage.Value = 0
plr.TStage.Value = 0
plr.Character:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages["0"].CFrame + Vector3.new(0, 3.78, 0)
game.ReplicatedStorage.ResetProgress:FireClient(plr)
local key = "ID_".. plr.UserId
local data = plr.leaderstats.Stage.Value
local success, error = pcall(function()
DS:SetAsync(key, data)
end)
if success then
print("Data saved: ".. key)
else
warn("Data ".. key.. " Unsuccessful when saving with error \"".. error.. "\"")
end
end)
I’m typing this on mobile so idk if it will work.
Edit:
I’m pretty sure this won’t work, but just put that snippet of code I added in wherever you award the players stages.
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore(tostring(Configurations.DataSaveString))
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
game:GetService("RunService").Stepped:Wait()
wait(.5)
chr:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages[tostring(plr.TStage.Value)].CFrame + Vector3.new(0, 3.78, 0)
chr.Humanoid.Died:Connect(function()
chr:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages[tostring(plr.TStage.Value)].CFrame + Vector3.new(0, 3.78, 0)
end)
end)
end)
repeat wait() until game.ReplicatedStorage.Configurations ~= nil
local Configurations = require(game.ReplicatedStorage.Configurations)
for _, v in pairs(workspace.Stages:GetChildren()) do
v.Touched:Connect(function(hit)
if v and v.Parent == workspace.Stages then
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr then
if Configurations.AdvanceAliveOnly == true then
if plr.Character:WaitForChild("Humanoid").Health > 0 then
if plr.leaderstats.Stage.Value == tonumber(v.Name) - 1 then
plr.leaderstats.Stage.Value += 1
plr.TStage.Value = plr.leaderstats.Stage.Value
elseif plr.TStage.Value < tonumber(v.Name) - 1 then
plr.TStage.Value += 1
end
end
else
if plr.leaderstats.Stage.Value == tonumber(v.Name) - 1 then
plr.leaderstats.Stage.Value += 1
plr.TStage.Value = plr.leaderstats.Stage.Value
elseif plr.TStage.Value < tonumber(v.Name) - 1 then
plr.TStage.Value += 1
end
end
end
end
end)
end
for _, v in pairs(workspace.Stages:GetChildren()) do
v.Touched:Connect(function(hit)
if v and v.Parent == workspace.Stages then
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr then
if Configurations.AdvanceAliveOnly == true then
if plr.Character:WaitForChild("Humanoid").Health > 0 then
if plr.leaderstats.Coins.Value == tonumber(v.Name) - 1 then
plr.leaderstats.Coins.Value += 1
plr.TCoins.Value = plr.leaderstats.Coins.Value
elseif plr.TCoins.Value < tonumber(v.Name) - 1 then
plr.TCoins.Value += 1
end
end
else
if plr.leaderstats.Coins.Value == tonumber(v.Name) - 1 then
plr.leaderstats.Coins.Value += 1
plr.TCoins.Value = plr.leaderstats.Coins.Value
elseif plr.TCoins.Value < tonumber(v.Name) - 1 then
plr.TCoins.Value += 1
end
end
end
end
end)
end
game.ReplicatedStorage.ResetProgress.OnServerEvent:Connect(function(plr)
plr.leaderstats.Stage.Value = 0
plr.TStage.Value = 0
plr.Character:WaitForChild("HumanoidRootPart").CFrame = workspace.Stages["0"].CFrame + Vector3.new(0, 3.78, 0)
game.ReplicatedStorage.ResetProgress:FireClient(plr)
local key = "ID_".. plr.UserId
local data = plr.leaderstats.Stage.Value
local success, error = pcall(function()
DS:SetAsync(key, data)
end)
if success then
print("Data saved: ".. key)
else
warn("Data ".. key.. " Unsuccessful when saving with error \"".. error.. "\"")
end
end)```