How to use FireServer() in PlayerRemoving

How could I send an event to the server before the character leaves :

this is my script

LOCAL:

game.Players.PlayerRemoving:Connect(function()
	game.ReplicatedStorage.BoostTimeSave:FireServer(game.ReplicatedStorage.TwoTimesOrbsMinutes, game.ReplicatedStorage.TwoTimesOrbsSeconds)
end)

SERVER:

game.ReplicatedStorage.BoostTimeSave.OnServerEvent:Connect(function(player, Minutes, Seconds)
	print(player.TimeLeft.ThreeTimesOrbsSeconds.Value, player.TimeLeft.ThreeTimesOrbsMinutes.Value)
	player.TimeLeft.ThreeTimesOrbsMinutes.Value = Minutes.Value
	player.TimeLeft.ThreeTimesOrbsSeconds.Value = Seconds.Value
end)
1 Like

Just track it on the server

2 Likes

how though that doesnt give any help

Instead of using a remote event to fire to the server, just put the server code in the playerRemoving on the server like this.

game.Players.PlayerRemoving:Connect(function(player)
	print(player.TimeLeft.ThreeTimesOrbsSeconds.Value, player.TimeLeft.ThreeTimesOrbsMinutes.Value)
	player.TimeLeft.ThreeTimesOrbsMinutes.Value = Minutes.Value
	player.TimeLeft.ThreeTimesOrbsSeconds.Value = Seconds.Value
end)
2 Likes

then it wont work, my data changes on the server

because its only changing on the client and it wont save on the server

Yes, so if it changes on the server you won’t have a problem because you’re doing everything on the server.

Track it on the server too

how though??? that doesnt help

If i save the data on the client when i join back it wont be on the server which holds the data store and wont save

you can’t save data on the client? what do you mean

because my data store that give it to the player is on the server

No need to fire an remote event whenever player leaves, you can just use playerremoving on server.

game.Players.PlayerRemoving:Connect(function(player)
      local Minutes = game.ReplicatedStorage.TwoTimesOrbsMinutes
      local Seconds = game.ReplicatedStorage.TwoTimesOrbsSeconds
      print(player.TimeLeft.ThreeTimesOrbsSeconds.Value, 
      player.TimeLeft.ThreeTimesOrbsMinutes.Value)
	  player.TimeLeft.ThreeTimesOrbsMinutes.Value = Minutes.Value
	  player.TimeLeft.ThreeTimesOrbsSeconds.Value = Seconds.Value
end)
1 Like

but I change the game.ReplicatedStorage.TwoTimesOrbsMinutes and game.ReplicatedStorage.TwoTimesOrbsSeconds on the client

You don’t need a client script.

what?? yes I do or the other part of my game wont work

The thing is that the client could also send fake numbers, to boost their stats if you do it this way. That’s why you should keep it on the server

how would I do it on the server if I dont want it to change for everyone

my full localscript:

local Id = 1268339333
local mps = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local breaking = false

script.Parent.MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(game.Players.LocalPlayer, Id)
end)

wait(3)

if game.Players.LocalPlayer:WaitForChild("AmountOwned").TimesThreeOrbs.Value ~= 0 and game.Players.LocalPlayer:WaitForChild("TimeLeft").ThreeTimesOrbsMinutes.Value ~= 0 and game.Players.LocalPlayer:WaitForChild("TimeLeft").ThreeTimesOrbsSeconds.Value ~= 0 then
	game.ReplicatedStorage.OrbsMultiplier.Value = 3
	local Minutes = game.ReplicatedStorage.TwoTimesOrbsMinutes
	local Seconds = game.ReplicatedStorage.TwoTimesOrbsSeconds
	Minutes.Value = game.Players.LocalPlayer.TimeLeft.ThreeTimesOrbsMinutes.Value
	Seconds.Value = game.Players.LocalPlayer.TimeLeft.ThreeTimesOrbsSeconds.Value
	if breaking == false then
		breaking = true
		while wait() do
			breaking = true
			repeat
				Seconds.Value -= 1
				wait(1)
			until Seconds.Value == 0
			if Seconds.Value == 0 then
				Minutes.Value -= 1
				wait(1)
				Seconds.Value = 60
			end
			if Minutes.Value and Seconds.Value == 0 then
				break
			end
		end
		game.ReplicatedStorage.OrbsMultiplier.Value = 1
		breaking = false
	end
elseif game.Players.LocalPlayer:WaitForChild("AmountOwned").TimesThreeOrbs.Value == 0 then
	print("is 0")
end

game.ReplicatedStorage.BoostPurchased.OnClientEvent:Connect(function(boostName)
	print("hello")
	if boostName == "TimesTwoOrbs" then


		game.ReplicatedStorage.BoostAdder:FireServer(boostName)
		script.Parent.Parent.Use.AmountAbleToUse.Value += 1


	end
end)

local Minutes = game.ReplicatedStorage.TwoTimesOrbsMinutes
local Seconds = game.ReplicatedStorage.TwoTimesOrbsSeconds

script.Parent.Parent.Use.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.OrbsMultiplier.Value = 3
	print("hi")
	if script.Parent.Parent.Use.AmountAbleToUse.Value > 0 then
		script.Parent.Parent.Use.AmountAbleToUse.Value -= 1
		game.ReplicatedStorage.BoostSubtracter:FireServer()
		if Seconds.Value == 0 then
			Seconds.Value = 60
			Minutes.Value += 9
		elseif Seconds.Value <= 60 and Seconds.Value > 0 then
			Minutes.Value += 10
		end
		if breaking == false then
			breaking = true
			while wait() do
				breaking = true
				repeat
					Seconds.Value -= 1
					wait(1)
				until Seconds.Value == 0
				if Seconds.Value == 0 then
					Minutes.Value -= 1
					wait(1)
					Seconds.Value = 60
				end
				if Minutes.Value and Seconds.Value == 0 then
					break
				end
			end
			game.ReplicatedStorage.OrbsMultiplier.Value = 1
			breaking = false
		end

	end
end)

game.Players.PlayerRemoving:Connect(function()
	game.ReplicatedStorage.BoostTimeSave:FireServer(game.ReplicatedStorage.TwoTimesOrbsMinutes, game.ReplicatedStorage.TwoTimesOrbsSeconds)
end)


Client isnt save, do all the value changing stuff from the server.
Exploiters can easily change those number values if its on client, exploiters can fire that remote event too.

how would i save it localy from the server without it changing for everyone