So I want to make a rebirth system using a module script and remote event but I don’t know how to:
Local Script:
for i,v in pairs(RebirthsModule) do
local CloneRebirthTemplate = RebirthTemplate:Clone()
CloneRebirthTemplate.Name = i
CloneRebirthTemplate.Cost.Text = v["Amount"] .. " Rebirths for " .. v["Cost"] .. " Cash"
CloneRebirthTemplate.Visible = true
CloneRebirthTemplate.Parent = RebirthFrame.Main.Scroll
end
for _,v in pairs(RebirthFrame.Main.Scroll:GetChildren()) do
if v:IsA("ImageLabel") then
v.Buy.MouseButton1Click:Connect(function()
Event:FireServer()
end)
end
end
Well, you’re on the right way, but you need to figure out a way of rebirthing, I don’t really understand the structure of the module, is it that rebirth 1-4 costs 100, rebirth 5-9 costs 500 and rebirth’s bigger than 10 cost 1000? Or is it how much does a amount of rebirth cost, 1 rebirth 100, 5 rebirths 500 and 10 rebirths 1000?
You are already connecting the client with server.
The only thing you should be passing through is only the amount of rebirths the player wants to buy. Not the cost, since that could be easily exploited.
You could require the amount that the player wants to buy by setting the name of the TextButton to the amount.
CloneRebirthTemplate.Name = v["Amount"] instead of CloneRebirthTemplate.Name = i
And then just Event:FireServer(tonumber(v.Buy.Name)) instead of Event:FireServer(amount)
and recieve it on server Event.OnServerEvent:connect(function(player, amount)) instead of Event.OnServerEvent:connect(function(player, cost, amount))
And then the listening should look something like this:
local RebirthModule = require(module) --Require the module that you've made with the information here
local function returnRebirthInfo(amount)
for i, info in pairs(RebirthModule)
if info.Amount == amount then
return info
end
end
return RebirthModule[1]
end
Event.OnServerEvent:Connect(function(player, amount)
local rebirthInfo = returnRebirthInfo(amount)
if rebirthInfo ~= nil then
if Player.leaderstats.Cash.Value > rebirthInfo.Cost then
Player.leaderstats.Cash.Value = 0
Player.leaderstats.Rebirths.Value += rebirthInfo.Amount
end
end
end)
This system should work with the structure of your current module. However it is overcomplicated and you could achieve less complex system by changing the structure of the module or not using the module at all, if you look at it, all your Cost values are just simply multiplications of the default cost Cost * Amount. So you don’t have to use the module at all.