Rebirth system for obby

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)
5 Likes

NONONONONO

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.

3 Likes

Alright thanks. I dont really understand remote events. Can you explain to me how I would do it?

2 Likes

Basically, player clicked. Fire tivservir!!!

--click event
Remote:FireServer()
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.

2 Likes

Do I need to add like a remote event inside the workspace or something? Because I’ve seen people do stuff like that.

2 Likes

Replicates storage is the best place imo

2 Likes


For some reason im getting red lines. I probably doing it wrong though

1 Like

Never mind I figured it out. Thanks for your help!

1 Like

THIS REMINDS ME
When you set a variable to something.Value it overwrites the variable instead. So you should do local stages = whatever
Stages.Value =

Just replace that everywhere. Also you were supposed to replace remote XD

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.