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

RemoteEvent:FireClient() cannot be used?

Asked by 3 years ago

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?

0
In your Script there is no parameter for Humanoid.Died just leave it blank MarkedTomato 810 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

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 googlpeopel15 55 — 3y
0
it did help me fix it as i just fixed it myself googlpeopel15 55 — 3y
Ad

Answer this question