Hello I am trying to make a rebirth system for my obby.
The script works for the most part already, meaning that when the player presses the button they get their rebirth. But for some reason its not taking away their stage number and its only adding a rebirth to the client. I think this is because its in a local script. Does anyone know how to add leaderstat values through local scripts, so that everyone can see them?
code:
script.Parent.MouseButton1Down:Connect(function(click)
local player = game:GetService('Players').LocalPlayer
local stage = player.leaderstats.Stage.Value
if stage == 100 then
stage = stage - 100
player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1
player.Character.Humanoid.Health = 0
game:GetService('SoundService'):PlayLocalSound(game.SoundService.achievement_complete)
print('Player has successfully Rebirthed!')
else
script.Parent.Parent.Parent.Parent.Parent["Rebirth conforma"].Visible = false
game:GetService('SoundService'):PlayLocalSound(game.SoundService.error)
script.Parent.Parent.Parent.Parent.Parent["Rebirth fail"].Visible = true
end
end)
If it’s client sided it won’t save because the server can’t see it. Not to mention they can lie. Fire a remote event to the server, check their stuff on the server and then rebirth if they are able to. Do not trust the client. They can spam rebirths. Add a cooldown on rebirths too so they don’t spam the server (via physical intvalue or table)
Also just set their stage to 0 instead of subtracting.
Remote.OnServerEvent:Connect(function(player) --player is automatically defined, you can also send variables via remotes
local stage = player.leaderstats.Stage.Value
if stage == 100 then
stage = 0
player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1
player.Character.Humanoid.Health = 0
game:GetService('SoundService'):PlayLocalSound(game.SoundService.achievement_complete)
print('Player has successfully Rebirthed!')
else
--have another remote with a local script that handles the reject. You specifically have to do :FireClient(player) as we want only 1 client to do this. Otherwise we would've used FireAllClients
end
end)
That’s it. I didn’t add cooldowns since I think they’d be kind of useless here.