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

How to use RemoteEvents, with FireServer?

Asked by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

Hey all! I'm a bit puzzled on how to use :FireServer(). No errors appear in the output, so I'm hoping You guys would be able to help. Thanks!

Local Script:

GUI = script.Parent.Parent.Parent.Parent
Frame = GUI.CitationsDB
Amount = Frame.Citation.Amount
Citee = GUI.Citee
Status = Frame.Status
Player = game.Players.LocalPlayer
Max = 250
RE = game.Workspace:WaitForChild("CitationScript"):WaitForChild("Event")

script.Parent.MouseButton1Down:connect(function()
    if not game.Players:findFirstChild(Citee.Value) then
        Status.Text = "PLAYER NOT FOUND!"
        wait(3)
        Status.Text = ""
    else
        local Victim = game.Players:findFirstChild(Citee.Value)
        if not tonumber(Amount.Text) then
            Status.Text = "INVALID AMOUNT"
            wait(3)
            Status.Text = ""
        else
            if (tonumber(Amount.Text) > Max) then
                Amount.Text = 250
            end
            local Response = game.ReplicatedStorage.Events.rFunction:InvokeServer("Subtract",(tonumber(Amount.Text)),Victim.Name)
            print(Response)
            if Response == "Transaction Completed." then
                Status.Text = "CITATION COMPLETED!"
                wait(3)
                Frame:TweenPosition(UDim2.new(0.5,-160,-1,-100),'Out','Quad',0.35)
                RE:FireServer(Player, Victim.Name, Amount.Parent.Reason.Text)
                wait(1)
                GUI:Destroy()
            else
                Status.Text = "PLAYER DOESN'T HAVE SUFFICIENT FUNDS!"
                wait(3)
                Status.Text = ""
            end
        end
    end
end)

script:

RE = script:WaitForChild("Event")

RE.OnServerEvent:connect(function(Player, Victim, Reason)
    if game.Players:findFirstChild(Victim) then
        local vic = game.Players:findFirstChild(Victim)
        game.Lighting.CitationNotif:clone().Parent = game.Players:findFirstChild(Victim).PlayerGui
        local GGUI = game.Players:findFirstChild(Victim).PlayerGui.CitationNotif
        GGUI.CitationNotif.Title.Text = Player.Name.." is charging you for '"..Reason.."'."
        GGUI.CitationNotif:TweenPosition(UDim2.new(0.5,-160,-0.5,-100),'Out','Quad',0.35)
    end
end)
0
I'd recommend putting print is several lines of code see where it stops. Question though, do you have a script handling invocations to rFunction, the code on line 25? Otherwise the script will just sit there. M39a9am3R 3210 — 9y
2
When you use :FireServer, the player instance is automatically the first argument of .OnServerEvent, so you don't need to provide one in the local script, else you'll return 4 arguments instead of 3. Redbullusa 1580 — 9y

1 answer

Log in to vote
3
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

If you were to add a print statement right in your listener function to print the arguments (Player, Victim, Reason) .. Victim would print in the place of Player, and Reason in the place of Victim... leaving "Reason" a nil argument.

Why..? Because the player argument is automatically passed as first argument when firing RemoteEvents and RemoteFunctions from the client. Therefore, all you really need to do is pass the arguments following it.

In your code, RE:FireServer(Player, Victim.Name, Amount.Parent.Reason.Text) would be RE:FireServer(Victim.Name, Amount.Parent.Reason.Text)

Ad

Answer this question