Change the button click, click value

Hello, i am new to scripting. And i don’t know how i can change the players click value when they click the button after they rebirth. Could you guys help me?

local rs = game:GetService("ReplicatedStorage")
local event = rs.RemoteEvent
local event2 = rs.RemoteEvent2
local clickval = 2
local rebirthval = 10


event.OnServerEvent:Connect(function(plr)
	plr.leaderstats.Clicks.Value += 1
end)

event2.OnServerEvent:Connect(function(plr)
	if plr.leaderstats.Clicks.Value >= rebirthval then
		plr.leaderstats.Clicks.Value -= rebirthval
		rebirthval *= rebirthval
	end
end)

Yes this seems to be a decent script but it looks like you’re using the wrong math operators?

event2.OnServerEvent:Connect(function(plr)
	if plr.leaderstats.Clicks.Value >= rebirthval then
		plr.leaderstats.Clicks.Value = 0 --resets clicks to 0
		plr.leaderstats.Rebirths.Value += 1 -- adds a rebirth value
	end
end)

From this I’m guessing you have a rebirth leaderstat as long as your click leaderstat. You can just set Clicks back to 0 to restart the progress. I’m not too sure why you’re multiplying rebirthval but I’ve just made it add to the rebirth leaderstat.

If you want each rebirth to be higher to get you can probably do a little formula based on how many rebirths the player currently has. multiplying the rebirthval will multiply it for everyone in the server too, not just that player.

If you want each rebirth to be harder to achieve just ask I’ll try and help.

Hello, thank you!
The reason why I was multiplying rebirthval is because I wanted to make the rebirth cost more each time, how could I only make the rebirth cost more on the local player?, this little project I’m making is just a clicker game. I just wanted to ask how could I increase the number of clicks ( the click button which gives 1+ clicks every time you click) the player gets after rebirthing?

You can try and calculate how many clicks you get based on your rebirth and how many clicked needed to reach the next rebirth.

For simplicity’s sake you can store these in functions to be called latter. I’m guessing you know how functions work but simply it helps do repetitive or specific jobs or “functions” multiple times. It works like a normal variable too.

function addition(a, b)
  return a+b
end
print(addition(4, 6)) -- 10

this how i would attempt your script.


local rebirthval = 20
function calculateClicksPer(rebirths)
  -- put this in a function so you can change it later
  return rebirths -- this is so if you're on a 4th rebirth, every click is 4 clicks
end

function calculateClicksNeededForRebirth(rebirths)
  -- 20 for first rebirth, 40 for second, 60 for third, 80, 100, 120 and so
  return 20*(rebirths+1) -- added 1 so you don't do 20*0 at 0 rebirths
end

event.OnServerEvent:Connect(function(plr)
    local rebirths = plr.leaderstats.Rebirths.Value
	plr.leaderstats.Clicks.Value += calculateClicksPer(rebirths)
end)
event2.OnServerEvent:Connect(function(plr)
    local rebirths = plr.leaderstats.Rebirths.Value
	if plr.leaderstats.Clicks.Value >= calculateClicksNeededForRebirth(rebirths) then
		plr.leaderstats.Clicks.Value = 0
        plr.leaderstats.Rebirths.Value += 1 -- add another rebirth
	end
end)

ofc include the variables at the top too

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