Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make this fe compatible?

Asked by 5 years ago

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
0
accept my answer since u said it helped Gey4Jesus69 2705 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.


Resources:

Remote Events


Accept and upvote if this helps!

0
Be careful with this solution, as server dosen't check if cash is >= 10000 and belives client that it is. It defeats the purpose of FE and could get exploited when your game becomes popular sleazel 1287 — 5y
0
good point Gey4Jesus69 2705 — 5y
Ad
Log in to vote
-1
Answered by
sleazel 1287 Moderation Voter
5 years ago
Edited 5 years ago

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.

1
a remote function is completely unnecessary. you should know this, because in your own code you arent even doing anything with the returned value on the client Gey4Jesus69 2705 — 5y
0
Relax man, I just choose remote function as player may not have enough money for rebirth and it is always nice to give feedback to player sleazel 1287 — 5y
0
thats not at all what remote functions are for. please read the wiki Gey4Jesus69 2705 — 5y
0
That is exactly what remote functions are for, events are for one way communication, functions are two way. You may use a seperate event to let know player that rebirth is not possible, but remote function is much more elegant. sleazel 1287 — 5y
View all comments (2 more)
0
first of all, you never explained how he could make a separate feedback system. second of all, it would be better to just nest another remote event inside the OnServerEvent to avoid the risk of the client no longer existing Gey4Jesus69 2705 — 5y
0
There is absolutely no difference between firing remote event to non existing player and returning value from remote function to non existing player. As I said, it is purely matter of preference, stop being such remote event nazi. And I already coded a feedback system all he needs to do is to replace print with appropriate GUI element text box update or something sleazel 1287 — 5y

Answer this question