Issue with event not firing

Hi! I’m trying to make an animated NPC walk up to you when you enter a certain hitbox/area and then, it will fire an event showing a GUI. But, I’m getting an error saying “FireClient: player argument must be a Player object”.
Neither the event nor the NPC is moving to the area it’s supposed to. I’ve looked all over the dev forum and I can’t find a solution.

SERVERSCRIPT in NPC

local NPC = script.Parent

local part1= game.workspace.MaxPathFindWalk

local runanimation = NPC.Run
local idleanimation = NPC.Idle

local runanimationtrack = NPC.Humanoid:LoadAnimation(runanimation)
local idleanimationtrack = NPC.Humanoid:LoadAnimation(idleanimation)
local debounce = false
script.Parent.LockOn.Touched:Connect(function(hit)
	if not debounce then
		debounce = true
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		game.ReplicatedStorage.TrainerEvents.TrainerBattleTrigger:FireClient(plr)

	--Walk to Targetted Part
	idleanimationtrack:Play()
	NPC.Humanoid:MoveTo(game.Workspace.MaxPathFindWalk.Position)
	idleanimationtrack:Stop()
	runanimationtrack:Play()
	NPC.Humanoid.MoveToFinished:Wait()
		idleanimationtrack:Play()
		
	end
	wait(5)
	debounce = false
end)
--Finish walking to targetted part

Localscript in StarterGUI

local plr = game.Players.LocalPlayer
game.ReplicatedStorage.TrainerEvents.TrainerBattleTrigger.OnClientEvent:Connect(function(plr)
	print("Trainer battle triggered by"..plr.name.."Battle UI popup fired")
end)

Is the NPC supposed to touch the part?

No, it’s standing right before the part.image

Does the error throw when the player touches the part?

1 Like

Yeah, right after you touch it, it errors out.

That’s weird. Could you try this and see what it prints?

debounce = true
print(hit.Parent, game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)) --Right here
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.TrainerEvents.TrainerBattleTrigger:FireClient(plr)

It printed “TopHat” and then errored right after.

Ok I think the hit is not a direct child of a Player character. Could you show the explorer when you are testing the game?

1 Like

Sure, But when I joined the game and pressed it now, it move to the correct position but it’s still giving me errors?image

1 Like

I was referring to your character.

1 Like

Ok, so apparently, when you go in and out of the area, it runs?

Oh, whoops. Here it is.

1 Like

Wait I posted this on the wrong post LOL my bad

1 Like

I think the problem is in the :GetPlayerFromCharacter. :GetPlayerFromCharacter function returns the Player associated with the given Player.Character , or nil. However, the plr that u r trying to pass in the :FireClient is not a player.

2 Likes