How can I make a rebirth system:
It’s really kind of self-explanatory. You need to store the number of rebirths a player has, and when the player presses the rebirth button with all conditions met, you increment that value. Then you reset all the player’s progress and increase their multiplier or anything else you want to do. It really depends on what you’re going for with it.
When I finish all of u said I gonna send it and u will tell me what to do again
As stated, its really self-explanatory
Store an number value representing the player’s current amount of coins;
And another one, which represents the player’s current amount of rebirths.
When the player requests to rebirth, either by clicking an button or by using an built-in feature, it will check if the player’s coin quantity is higher or equal than a minimum, let’s say, by default, 50.
The basic logic for this is implemented as follow:
local Coins = Instance.new("NumberValue")
local Rebirths = Instance.new("Rebirths")
Coins.Name = "Coins"
Rebirths.name = "Rebirths"
local DefaultMinimum = 50
local function Rebirth()
Coins.Value = 0
Rebirths.Value += 1
end
function RequestRebirth()
if Currency.Value >= DefaultMinimum then
Rebirth()
end
end
An additional function could be implemented to make the coins minimum amount be set accordingly to the player’s current amount of rebirths:
Function that doubles the default minimum amount (which is 50) every rebirth.
function Minimum()
if Rebirths.Value > 0 then
return DefaultMinimum *(Rebirths.Value /2)
else
return DefaultMinimum
end
end
Whole implementation:
local Coins = Instance.new("NumberValue")
local Rebirths = Instance.new("Rebirths")
Coins.Name = "Coins"
Rebirths.name = "Rebirths"
local DefaultMinimum = 50
local function Rebirth()
Coins.Value = 0
Rebirths.Value += 1
print("Just rebirthed")
print("Current amount of rebirths:", Rebirhs.Value)
-- Do additional things
end
function Minimum()
if Rebirths.Value > 0 then
return DefaultMinimum *(Rebirths.Value /2)
else
return DefaultMinimum
end
end
function RequestRebirth()
if Currency.Value >= Minimum() then
Rebirth()
end
end
Please note that, as stated, this is a basic (raw) implementation of a rebirth feature.
Do you recommend I use remote events?
Yes, that’s the recommended approach.
A bad practice is to include client-side logic along with the server.
In cases where the game fills up with players, the server’s ability to respond to events would be reduced because it has to handle both its logic and the client’s interactivity. Additionally, doing this can make the game messy, as you need to program the same client-side part where you program the server-side’s logic, making it more challenging to make changes and develop both sides without functionality overlap.
For example:
Instead of creating a specific signal to trigger a certain UI reaction, create a signal that communicates what happened and let the client-side react.
Putting this into practice:
In a match-based game, the match has ended, and you need to display an end-of-match screen.
Instead of creating a remote event like “DoEndScreen,” create a remote event called “MatchEnded,” with the reaction to this signal being handled on the client-side, which will display the end screen and perform additional tasks. This makes it easier to develop and change how both parts function.
Or even, applying this in the context of a rebirth implementation:
The player requests to do rebirthing through a remote function. The server should then process its logic and return a value indicating success or failure, and then the client should take care of the rest; Either by indicating success or by indicating failure.
Applying this example in practice:
-- Server;
-- Altered "Rebirth" function to do only what it is supposed to do, without printings.
function Rebirth()
Coins.Value = 0
Rebirths.Value += 1
end
-- Altered "RequestRebirth" function to return a boolean indicating success or failure;
function RequestRebirth()
if Currency.Value >= Minimum() then
Rebirth()
return true
end
return false
end
local RequestRebirth = game.ReplicatedStorage.Events.RequestRebirthing
RequestRebirth.OnServerEvent:Connect(RequestRebirth)
local AskRebirthing = game.ReplicatedStorage.Events.RequestRebirthing :: RemoteFunction
local Button = script.Parent
local CoinsAmount = "PATH" -- Path to 'Coins' number value here
local RebirthsAmount = "PATH" -- Path to 'Rebirths' number value here.
local DefaultMinimum = 50;
local function LocalMinimum()
if RebirthsAmount.Value < 1 then
return DefaultMinimum
else
return DefaultMinimum *(RebirthsAmount.Value /2)
end
end
local function Rebirth()
local CouldRebirth = AskRebirthing:InvokeServer()
if CouldRebirth then
print("Local client: Just rebirthed")
print(`Current coins amount: {CoinsAmount.Value}`)
print(`Current rebirths amount: {RebirthsAmount.Value}`)
print(`Minimum coins for next rebirth: {LocalMinimum()}`)
-- Do additional functionality.
else
print("Could not rebirth; Some internal error ocurred")
end
end
Button.MouseButton1Down:Connect(function()
-- Doing a small check to avoid performing unnecessary calls to the server;
if CoinsAmount.Value < LocalMinimum() then
warn(`Local Client: You cannot afford to do rebirthing right now.`)
return
end
Rebirth()
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.