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

RemoteEvent:FireClient() passing argument as nil?

Asked by
asgm 109
5 years ago

I'm trying to make a server chat message for the client, but somehow when I pass a player argument for :FireClient(), it went missing when it reaches the message script.

This is the :FireClient() message (server script):

1local MessageEvent =
2            game:GetService("ReplicatedStorage").EventsFolder.ServerMessageEvent
3local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
4local text = "You have been given "..Points.Value..
5        " Points for completing the map with the score of "                                         
6                    ..Score.Value
7MessageEvent:FireClient(Player,text) 

And this is the local script that's supposed to fire:

01MessageEvent = game:GetService("ReplicatedStorage").EventsFolder.ServerMessageEvent
02 
03MessageEvent.OnClientEvent:Connect(function(Player,text)
04    print(text)
05    print(Player)
06    game.StarterGui:SetCore("ChatMakeSystemMessage",{
07    Text = ("[Server]:"..text);
08    Font = Enum.Font.SourceSansBold;
09    Color = Color3.new(237, 255, 114);
10    FontSize = Enum.FontSize.Size18})
11 
12 
13end)

And this is what it prints out: (the first 2 lines are from FireAllClients,which sends the server message to the whole server.) (server chat messages are client-sided,which is why i'm doing this)

1asgm has beaten The First Map with the score of 11!
2asgm
3  nil
4  You have been given 6 Points for completing the map with the score of 11
5  08:23:43.633 - Players.asgm.PlayerGui.ServerMessage:17: attempt to concatenate local 'text' (a nil value)

as you can see, print(Player) prints out the text instead of "asgm" while (text) goes missing. When I remove the "Player" argument, it prints out this:

1asgm has beaten The First Map with the score of 11!
2asgm
308:16:20.382 - Unable to cast value to Object

Is there something I'm missing? (forgive me if my use of the word "argument" is misleading i don't use it quite often since i often get confused with the term "argument" and "parameter")

0
Don't send me wiki links unless necessary to overcome my stupidity, I understand english good,but Lua bad. asgm 109 — 5y
0
OnClientEvent only requires the arguments that you're sending, not the player. When you removed the player from line 3 in the LocalScript, did you also remove line 5? https://developer.roblox.com/en-us/api-reference/event/RemoteEvent/OnClientEvent InfinitivePixelsJr 542 — 5y
0
Oh,really? I thought client events automatically creates or sets a player argument as the first argument,wether there's no argument or there's 1 argument. and yes,I think the (text) argument is nil which is why it throws an error. I solved this by rearranging the arguments to (text,Player) instead of (Player,text) which I should've thought earlier :/ (Player is still nil, how do you get player?) asgm 109 — 5y

Answer this question