Hello! I am trying to make it so a UI appears when the player dies. To do this i am using a remote event:FireClient() but for some reason it doesnt quite work. and i get a error FireClient: player argument must be a Player object
Here is the code:
Server Script (In ServerScriptService)
local gameoverevent = game.ReplicatedStorage:WaitForChild("GameOver") local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoid = character:WaitForChild("Humanoid") humanoid.Died:Connect(function(player) gameoverevent:FireClient(player) end) end) end)
Local Script (In StarterPlayerScripts):
local gameoverevent = game.ReplicatedStorage:WaitForChild("GameOver") local playergui = script.Parent.Parent:WaitForChild("PlayerGui") local gameover = playergui.GameOver gameoverevent.OnClientEvent:Connect(function(player) gameover.Enabled = true gameover.GAMEOVER:Play() end)
Im not quite sure what im doing wrong here. Any reason why?
The RemoteEvent:FireClient()
seems to be just fine in the normal Script
, however I see 2 mistakes with your LocalScript
:
Instead of using Gui.Enabled, you should use Gui.Frame.Visible since it's the most common way of displaying Guis
Since you already passed the player argument on you could reference PlayerGui directly instead of writing script.Parent.Parent...
, like this:
gameoverevent.OnClientEvent:Connect(function(player) local PlayerGui = player.PlayerGui local GameOver = PlayerGui:WaitForChild("GameOver") -- You also have to use WaitForChild() since ROBLOX will always read your Gui as "nil" when starting, because hasn't replicated it to the client yet. gameover.Frame.Visible = true -- idk if you have 1 or multiple frames here, if you have more than 1 use an "In Pairs" loop to make visible all the frames. gameover.GAMEOVER:Play() end)
Hope this solves your question.