FireClient must be a player object problem

Hello, I was coding a monster that kills the specific player that touched the monster’s HumanoidRootPart, however I also need to fire a remote event to enable death scene, but whatever I do, it’s not firing the remote event for the specific player, I tried getting the player character but still, it’s gives me the same error, it’s says “FireClient: player arguement must be a Player object”

image

the problem is in the line 25 in the code

Here’s my code also:

Well you don’t actually know what the object it hit was currently as there are no checks so this could be erroring because the rest of the body parts from the monster are touching it

Yes, I also noticed that while testing, the script executes itself automatically, even tho I didn’t even touch it

add a if not player then return end after line 17

Yes I did that, I realized the monster was touching it’s own humanoidrootpart so I added “if player and not player.Character:FindFirstChild(“Cost”) then” then it worked, thanks! I was really confused

The first two variables within the function (the ones that try to retrieve a Player object and find the Humanoid of the Character model) are never checked to make sure that it actually found those objects before firing the RemoteEvent.

Making sure those exist (most importantly, the player) before firing the RemoteEvent should resolve the issue

Example Revision

-- Everything else above this section of code should be able to remain the same

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

myHumanoidRootPart.Touched:Connect(function(obj)
    if debounce == false then
        debounce = true

        print(obj.Parent)
        local Character = obj:FindFirstAncestorOfClass("Model")
        local Humanoid = Character:FindFirstChildOfClass("Humanoid")

        if not Character and not Humanoid then return end

        local player = Players:GetPlayerFromCharacter(Character)
        local Cost = Character:FindFirstChild("Cost")

        if player and not Cost then
            ReplicatedStorage.NewDeathCamRemote:FireClient(player, myCamPart, camDuration)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.