You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Hello! I have a game where you skydive, collection points and coins and those save. -
What is the issue? Include screenshots / videos if possible!
The issue is that all players have a fixed amount of Glory Points and Glory Coins. When I printed the value out in the output, it gave the actual value. But the leaderstats still appears fixed. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have not found much topics like this. If you have any suggestions or solutions, please list them down below.
Module
local mod = {}
local minimumPlayers = 1
local gameTime = 10
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local Skydive = RemoteEvents:WaitForChild("Skydive")
local SoundService = game:GetService("SoundService")
local GlobalSounds = SoundService.GlobalSounds
local CountdownSound = GlobalSounds.CountdownSound
local debounce = false
function mod:Intermission(Players, Status, Intermission, IntermissionLength)
local function EnoughPlayers()
for i = 0, 3, 1 do
Status.Value = "Waiting for more players to join"..string.rep(".", i)
task.wait(1)
end
end
repeat EnoughPlayers() task.wait() until #Players:GetPlayers() >= minimumPlayers
repeat task.wait() until #Players:GetPlayers() >= minimumPlayers
-- set the intermission value to true
Intermission.Value = true
for i = IntermissionLength, 0, -1 do
Status.Value = "Intermission: "..tostring(i)
task.wait(1)
end
Intermission.Value = false
end
function mod:StartRound(Players, Status, Arena, TeleportTo)
-- start the round
for i, player in pairs(Players:GetPlayers()) do
local Character = player.Character or player.CharacterAdded:Wait()
if Character then
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
player:SetAttribute("InRound", true)
if player:GetAttribute("InRound") then
HumanoidRootPart:PivotTo(TeleportTo.CFrame)
Skydive:FireClient(player)
end
end
end
end
for i = 3, 1, -1 do
Status.Value = tostring(i).. "..."
CountdownSound:Play()
task.wait(1)
end
CountdownSound:Play()
Status.Value = "GO!"
Arena.BrickColor = BrickColor.random()
task.wait(2)
Arena.CanCollide = false
Status.Value = "Round in progress!"
end
function mod:EndRound(Players, Status, Arena, Target, LobbySpawn, RoundEnded)
-- end the round
local Winners = {}
local rewardedGloryPoints = math.random(100, 300)
local rewardedGloryCoins = math.random(25, 50)
local rewardChance = math.random(1, 4)
local rewardBoost = 2
local function NoWinners()
task.wait(35)
if #Winners == 0 then -- if there are no winners after 35 seconds.
Status.Value = "No winners! Disbanding round!"
if Arena.CanCollide == false then
Arena.CanCollide = true
end
end
end
Target.Touched:Connect(function(Hit)
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
if not table.find(Winners, Player) then -- if it's not the same player.
table.insert(Winners, Player) -- then insert them into the table.
end
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character then
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
Player:SetAttribute("InRound", false)
if not Player:GetAttribute("InRound") then
HumanoidRootPart:PivotTo(LobbySpawn.CFrame + Vector3.new(0, 10, 0))
end
Arena.CanCollide = true
for i, winner in pairs(Winners) do
if table.find(Winners, Player) then -- checks if the player is a winner.
if not debounce then
debounce = true
Status.Value = "Winner(s): "..winner.Name
if rewardChance == 3 then
-- doubles rewards gained from round.
Player.leaderstats["Glory Points"].Value += rewardedGloryPoints * rewardBoost
Player.leaderstats["Glory Coins"].Value += rewardedGloryCoins * rewardBoost
else
Player.leaderstats["Glory Points"].Value += rewardedGloryPoints
Player.leaderstats["Glory Coins"].Value += rewardedGloryCoins
end
task.wait(3)
debounce = false
end
end
task.wait(1)
end
table.clear(Winners) -- clears the table of previous winners.
RoundEnded.Value = true
task.wait(3)
RoundEnded.Value = false
end
end
end
end)
NoWinners()
end
return mod
Normal Script
local DataStoreService = game:GetService("DataStoreService")
local Currencies = DataStoreService:GetDataStore("Currencies")
game.Players.PlayerAdded:Connect(function(Player) -- When the player joins the game.
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local GloryPoints = Instance.new("IntValue")
GloryPoints.Name = "Glory Points"
GloryPoints.Value = 0
GloryPoints.Parent = leaderstats
local GloryCoins = Instance.new("IntValue")
GloryCoins.Name = "Glory Coins"
GloryCoins.Value = 0
GloryCoins.Parent = leaderstats
local Data
local success, errormessage = pcall(function()
Data = Currencies:GetAsync("-globalcurrencies")
end)
if success then
GloryPoints.Value = Data[1]
GloryCoins.Value = Data[2]
print("Successfully got currencies.")
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(Player) -- When the player leaves the game.
local leaderstats = Player.leaderstats
local saveData = {}
for i, currency in ipairs(leaderstats:GetChildren()) do
table.insert(saveData, currency.Value)
end
local success, errormessage = pcall(function()
Currencies:SetAsync("-globalcurrencies", saveData)
end)
if success then
print("Successfully set currencies.")
else
warn(errormessage)
end
end)