I just need help making it fe compatible with remote events. I have one called Rebirth but i don't know why its not working when I do make it fe compatible so here is the original script.
button = script.Parent player = game.Players.LocalPlayer button.MouseButton1Click:Connect(function() if player.leaderstats.Cash.Value >= 10000 then player.leaderstats.Cash.Value = 0 player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1 player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 150 end end
You're right about having to make this compatible with Filtering Enabled
. Changes to the client or objects inside the client will not be replicated to the server, unless of course the server makes the change. To fix this, we'll handle the MouseButton1Click
event on the client and the actual changing of values on the server.
--Server Script local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = Instance.new("RemoteEvent") Remote.Parent = ReplicatedStorage Remote.OnServerEvent:Connect(function(player,check) if check == "Rebirth" and player.leaderstats.Cash.Value >= 10000 then --check info the client sent player.leaderstats.Cash.Value = 150 --you were setting this to 0 and then adding 150 to it, but it will always be 150, because 0 + 150 = 150. player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1 end end)
--Local Script local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = ReplicatedStorage:WaitForChild("RemoteEvent") local button = script.Parent button.MouseButton1Click:Connect(function() Remote:FireServer("Rebirth") --send conditions with the remote to ensure safety. end)
If you have any questions, feel free to leave them in the comments.
I am assuming you are trying a to code a rebirth button? Edit your local script like this:
button = script.Parent player = game.Players.LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local RebirthRequest = ReplicatedStorage:WaitForChild("RebirthRequest") button.MouseButton1Click:Connect(function() local result = RebirthRequest:InvokeServer() print(result) --delete later, after making sure it works end)
And add this script to your ServerScriptStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage") local RebirthRequest = Instance.new("RemoteFunction") RebirthRequest.Parent = ReplicatedStorage RebirthRequest.Name = "RebirthRequest" local function onRebirthRequest(player) if player.leaderstats.Cash.Value >= 10000 then player.leaderstats.Cash.Value = 0 player.leaderstats.Rebirths.Value =player.leaderstats.Rebirths.Value + 1 player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 150 --not needed, just set it to 150 instead of 0 two lines before... return "Success" else return "Not enough money..." end end RebirthRequest.OnServerInvoke = onRebirthRequest
I hope this helps...
Edit: gioni01 islution is very good aswell, it is up to you wheather you choose remote function or event. Functions are better if you require feedback from server, if not then use events as they do not yield.