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)
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
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)
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.
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)
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?