Need help with firing Remote Event for a single client

Hello there,
So im trying to fire a remote event from server to a single client through surface GUI.
The problem im running into is that the player object is missing.
I have looked through the Roblox forums and even tried to get help from some friends but had no luck.

local remoteEvent = game.ReplicatedStorage.RemoteEvent

local function Fire(player)

remoteEvent:FireClient(player:GetPlayerFromCharacter(player))

end

script.Parent.MouseButton1Click:Connect(Fire)
1 Like

If this is a SurfaceGui, can’t you just put the SurfaceGui in StarterGui and set the Adornee property to the part to display it on and make the script a localscript?

It’ll remove the need to have to somehow get the player from the server

Also MouseButton1Click returns nothing, if you do what I say you can just get the LocalPlayer fomr game:GetService("Players").LocalPlayer

Try doing what I had mentioned, putting it in StarterGui, setting the adornee to the part to display it on, make it a localscript, and just changing the localscript’s code to the code you wanted to do when the button is pressed for a client

Also what are you doing

Sorry the script was supposed to be

local Players = game:GetService("Players")

local remoteEvent = game.ReplicatedStorage.RemoteEvent

local function Fire(player)
	remoteEvent:FireClient(player:GetPlayerFromCharacter(player))
end
script.Parent.MouseButton1Click:Connect(Fire)

Alright I will try to do the same

correction* local Players = game:GetService("Players").LocalPlayer – to get the current player (you) from the player service (player list).

Also remove “player” from the fire function and replace player:GetPlayerFromCharacter(player) to FireClient(player) because you are already given the direct reference of a local player from PlayerService.

Ok thanks, Will make the change in the code

Attempt to index nil with ‘GetPlayerFromCharacter’

Did you replace the code as I stated?

Yep I did as you stated, and still got the error

Then you shouldn’t be receiving this error, unless it is from elsewhere.
Could you share the updated code?

local player = game:GetService(“Players”).LocalPlayer

local remoteEvent = game.ReplicatedStorage.SuggestFolder.OpenGuiEvents.Truth

script.Parent.MouseButton1Click:Connect(function(player:GetPlayerFromCharacter(player))

remoteEvent:FireClient(player)

end)

Im bad at coding currently so if there is a mistake correct me

Correction* You do not need player:GetPlayerFromCharacter

local player = game:GetService(“Players”).LocalPlayer
local remoteEvent = game.ReplicatedStorage.SuggestFolder.OpenGuiEvents.Truth
script.Parent.MouseButton1Click:Connect(function()
	remoteEvent:FireClient(player)
end)

Error is : FireClient: Player argument must be a object

Do not copy and paste, fix the quotation mark on this:

I did the same, I replaced the ("Players") manually
1 Like

The script is from the server, so using Local Player wont work.
Since it’s a SurfaceGUI, just parent it to StarterGui, and set its Adornee to the part you want it to show on.

This way, you can get the player locally.
Use a Local Script instead of a script, since its from the client.

script.Parent.MouseButton1Click:Connect(function()
--whatever you want
end)

Woops! This is incorrect because you are using serverscript, not a local script. My apologies. When exactly do want the event to fire? Is it upon player joining?

I will have to Duplicate the GUI on several Parts, So Having 10-15+ GUI in starter GUI is a lot

When player clicks a button from the gui