How do i increment a players Rebirths through a TextButton using DataStore2?

  1. What do you want to achieve? I want to be able to increment a players Rebirths when a textbutton is clicked using DataStore2

  2. What is the issue? I can’t find a way to do what i said in the first question

  3. What solutions have you tried so far? I have looked everywhere, Youtube, ScriptingHelpers and the DevForum

I do not have a datastore2 script yet since im looking for a way to increment an IntValue by clicking on a TextButton, i have however tried using Increment() to increment the Rebirths but that does not work, only when i do so in a Part.
I am not super good with scripting but i have some knowledge :slight_smile:

3 Likes

Use a RemoteEvent to send a “rebirth request” to the server. Then validate the request on the server and if it’s valid, give them the rebirth:

--client, LocalScript
local Remote = game.ReplicatedStorage.RebirthRequest --remote
local Button = script.Parent --rebirth UI button

--when the button is pressed
Button.Activated:Connect(function()
	--make the request 
	Remote:FireServer()
end)
--server, Script
local Remote = game.ReplicatedStorage.RebirthRequest --remote

--a validate function which returns true or false, based on if the player has enough currency
--replace the condition below with an actual condition
function Validate(player)
	local player_has_enough_levels = true 
	if player_has_enough_levels then 
		return true 
	else 
		return false 
	end
end

--listen to the request
Remote.OnServerEvent:Connect(function(player)
	if Validate(player) then 
		player.Rebirths += 1 --or IncrementAsync etc.
		--also remove their currency, do necessary calculations so it can't be spammed
	end
end)
1 Like

Can people not exploit remote events tho? Or is there something in the Datastore2 that prevents them from doing so?

That’s why we make the validation on the server. So people can’t get infinity rebirths by manually spamming the remote with fake validations.

1 Like

Alright, thanks man, you just saved me a bunch of time! :smiley:

1 Like