Problem with rebirthing?

Hello! In my simulator game there is a problem with the rebirth system. The script is in ServerScriptService but I’m not sure if the code is right. The problem is that whenever someone rebirths it gives them 1000 rebirths except for 1. It also has a problem after rebirthing and it increases their strength a lot more than it is used to. I appreciate any help! Here is the code:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local starterRebirthAmount = 5000

local cooldown = 1

replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
	
	if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
	
	local debounce = remoteData [player.Name].Debounce
	
	if not debounce.Value then
		debounce.Value = true
		
		player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 25 * (	player.leaderstats.Rebirths.Value + 0.5)
		
		wait(cooldown)
		
		debounce.Value = false
	else
		
	end
end)

replicatedStorage.Remotes.Rebirth.OnServerInvoke = function(player)
	
	if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
	
	local rebirths = player.leaderstats.Rebirths
	
	if player.leaderstats.Strength.Value >= (math.floor((starterRebirthAmount + (rebirths.Value) + math.sqrt(50000000)))) then
		
		rebirths.Value = rebirths.Value + 1000
		
		player.leaderstats.Strength.Value = 0
		
		player:LoadCharacter()
		
		return true
	else return "NotEnoughStrength"
	end
end
1 Like

This is the problem, you’re increasing the rebirths value by 1000.

1 Like

I find your code quite hard to read in the first place. There is no need to seperate each line with a blank line.

Also, what does this do?

That is to lift to get strength

1 Like

Oh ok let me change it to 1 and see if it works

1 Like

Tried and it didn’t work :frowning: do you have any other ideas why it’s not working?

Can you please post your updated code?

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local starterRebirthAmount = 5000

local cooldown = 1

replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
	
	if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
	
	local debounce = remoteData [player.Name].Debounce
	
	if not debounce.Value then
		debounce.Value = true
		
		player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 25 * (	player.leaderstats.Rebirths.Value + 0.5)
		
		wait(cooldown)
		
		debounce.Value = false
	else
		
	end
end)

replicatedStorage.Remotes.Rebirth.OnServerInvoke = function(player)
	
	if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
	
	local rebirths = player.leaderstats.Rebirths
	
	if player.leaderstats.Strength.Value >= (math.floor((starterRebirthAmount + (rebirths.Value) + math.sqrt(50000000)))) then
		
		rebirths.Value = rebirths.Value + 1
		
		player.leaderstats.Strength.Value = 0
		
		player:LoadCharacter()
		
		return true
	else return "NotEnoughStrength"
	end
end
1 Like

I was thinking about that, but then I got confused by this. 5000 seems like a lot in comparison to 1.

This looks a bit overcomplicated. Why is math.sqrt(50000000) in there?

1 Like

They probably have followed a tutorial by AlvinBlox.

1 Like

Yea I wanted to make a simulator game so I followed the video

5000 is the amount of strength you need to rebirth.

Ok, I see and you want to make it harder for stronger people to perform a rebirth. This might be a bit easier to understand and read:

local strength = player.leaderstats.Strength.Value
-- Makes it exponentially harder when getting more rebirths
local rebirthStrength = starterRebirthAmount + rebirths.Value ^ 1.5
if strength >= rebirthStrength then
      -- Allow rebirth
end

1000 should be 1 as mentioned earlier. Could you explain what is happening exactly, since this did not work?

That should be the value of the rebirths. I switched it to 1 but for some reason it is still adding 1000 everytime I rebirth. I published it 8 times and it still didn’t work.

Are you trying it in-game? If so, then go ahead and give it a try in the studio, I’ve been using your code in a baseplate and it seems to be working perfectly fine for me.

Ok I’ll try it in studio and I’ll tell you if it works or not

1 Like

Ok so it works in studio but not in-game

Did you publish your game via ROBLOX Studio before trying it on ROBLOX Player?

Yes I published it before I played it in-game and I rejoined multiple times

You should publish your game every time before you want to play it using ROBLOX Player.