Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

RemoteEvent:FireClient() cannot be used?

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?

1 comment

0

In your Script there is no parameter for Humanoid.Died just leave it blank

1 answer

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.

2 comments

0

This does not solve my question as it does not solve the actual error. The error is in the server script at line 8

0

it did help me fix it as i just fixed it myself

This discussion is preserved as it was. New answers, comments, and votes are closed.