I'm new to RemoteEvents. Help!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I need my FireClient() Event to return the right arguments

  2. What is the issue? Include screenshots / videos if possible!
    Here is a piece of the code that should return different arguments when the game is over. The player argument should return a player but it returns the WinBonus, and the Winbonus Returns the PlayersLeft value and so on.

-- Localscript in PlayerGui
game:GetService("ReplicatedStorage"):WaitForChild("Won").OnClientEvent:Connect(function(Player, WinBonus, PlayersLeft, OwnsGamePass, Multiplier)

-- Main Script in Workspace
game:GetService("ReplicatedStorage"):WaitForChild("Won"):FireClient(plr, 0, 0, game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,47007279), plr:WaitForChild("Multiplier").Value)

I know it has something to do with FireClient returning Player by default but I am unable to fully understand it. Thanks in advance!

Sincerely,
Mathe

1 Like

When you’re firing client, the first argument is referred to that player, but if you want to do something with that player, you’ll need to pass him as another argument.

Also, I am confused. Why passing game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,47007279),
you can simply check if he owns that gamepass on the server.

if you have not already this is also a good article to read

-- server script

local replicatedStorage = game:GetService("ReplicatedStorage")
local wonEvent = replicatedStorage:WaitForChild("Won")
wonEvent:FireClient(player, 0, 0)

-- local script

local marketplaceService = game:GetService("MarketplaceService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.Localplayer
local wonEvent = replicatedStorage:WaitForChild("Won")
local multiplier = player:WaitForChild("Multiplier")

wonEvent.OnClientEvent:Connect(function(WinBonus, PlayersLeft)
    local hasGamePass = marketplaceService:UserOwnsGamePassAsync(player.UserId, 47007279)
    print(WinBonus, PlayersLeft, hasGamePass, multiplier.Value)
end)
1 Like

Seems like the problem is in your local script. RemoteEvent.OnClientEvent() do not take “Player” as a parameter. That is because, the client is the player themselves.

So what you should do is remove the player parameter from the function within your local script.

1 Like

So how do I implement this into the localscript? : )

game:GetService("ReplicatedStorage"):WaitForChild("Won"):FireClient(plr,realplr, 0, 0, game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,47007279), plr:WaitForChild("Multiplier").Value)
game:GetService("ReplicatedStorage"):WaitForChild("Won").OnClientEvent:Connect(function(Player, WinBonus, PlayersLeft, OwnsGamePass, Multiplier)

The second argument in the fireclient will always be the first one in the client call [ the auto player is already there]

1 Like

Instead of:

game:GetService("ReplicatedStorage"):WaitForChild("Won").OnClientEvent:Connect(function(Player, WinBonus, PlayersLeft, OwnsGamePass, Multiplier)

Do:

game:GetService("ReplicatedStorage"):WaitForChild("Won").OnClientEvent:Connect(function(WinBonus, PlayersLeft, OwnsGamePass, Multiplier)

What I did is removed the “Player” parameter from your OnClientEvent function in your local script.

1 Like

But the Player is still defined though?

I made this the solution in advance :slight_smile:

Since that code is in your LOCAL script, if you ever need your player to be referenced anytime, you can just reference the local player in your local script by doing…

local player = game.Players.LocalPlayer

That way, you can access the player anytime. You do not need to have the player referenced by a remote event fired by the server.

1 Like

To make things clear…

You can receive and fire RemoteEvents inside the server or the client. Only the server side will accept and take in Player parameter and argument. That is because, the server does not know which player the code wants it to do something with. So you should pass in a player
as the first argument if you’re doing RemoteEvent:FireClient(Player, extra args**), or parameter if you’re doing RemoteEvent.OnServerEvent(Player, extra params**), so the server knows which player to take care of.

On the other hand, clients can only receive other values or information from the server. You do not need to take in Player as a parameter or an argument within the client when dealing with RemoteEvents.

If you need to have a player referenced in your local script, just reference the local player so you can access it anytime.

Have a good day! :+1:

2 Likes

I’m so dumb :sob:

Thank you though!