Need help adding leaderstats after round

Hello reader,

I am trying to make the script so that once the round is over if the player survived then it will add 100 to there leaderstats (the leaderstats is called “Money”) I tried and tried but it just broke my script so I came here for help I hope someone can help and here is my script:

local lobbyLocation = game.Workspace.Lobby.Position + Vector3.new(0,3,0)

local gameLocation = game.Workspace.Main.Position + Vector3.new(0,3,0)

local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)

local timeEvent = ReplicatedStorage:WaitForChild(‘TimeEvent’)

local function playGame()
local player = game:GetService(‘Players’).LocalPlayer
local timeAmount = 160
local timerText = "Remaining Time: "

while timeAmount > 0 do
timeEvent:FireAllClients(timeAmount, timerText)

  wait(1)
  
  timeAmount -= 1

end
end

local function playIntermission()

local intermission = 30

local timerText = 'Intermission: ’

while intermission > 0 do

  timeEvent:FireAllClients(intermission, timerText)

  wait(1)

  intermission -= 1

end

end

local function resetPlayers()

for _, plr in pairs(game.Players:GetChildren()) do

  plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbyLocation)

end

end

local function teleportPlayers()

for _, plr in pairs(game.Players:GetChildren()) do

  plr.Character.HumanoidRootPart.CFrame = CFrame.new(gameLocation)

end

end

while true do

resetPlayers()

playIntermission()

teleportPlayers()

playGame()

end

So thats my script any help is appreciated thanks.

1 Like

I think people dont respond you because of your weird code formation and also when I read the code I was a bit confused… how can “game.Players.LocalPlayer” and “remote:FireAllClients()” be found in the same script?

1 Like

Hmm. Just as the other guy said, your script is pretty confusing. If you really want feedback, I recommend doing these things:
Be more specific. You just said “it just broke my script” ,you can use print statements to find out where the script breaks.
Explain after every line in the script what the line does and why. Example:
Local message = "hello" -- making a variable to print it out later...
Doing this makes it so much easier for people to understand your script and it will make it easier to help you. I hoped this helped you!

local function AddLeaderstat(LeaderStatname,Value,Player)
      Player.leaderstats:FindFirstChild(Leaderstatsname)Value += Value
end

Does this help? Or is it something else your looking for?

Yes it is exactly what I’m looking for thank you but one question is where would I add this I’m a bit new but I know a bit.

I’m sorry for the inconvenience in my script thank you for the feedback I will do that next time

1 Like

you just add it anywhere in the script, then call it when the round is over. Mabey when cycling through the teleporting you can call it

Ok thank you so much it will help me alot

1 Like