Player Argument must be a Player Object Problem

I am trying to make it so that when a player touches a brick, an event is fired. Instead, it is coming up with “Player Argument must be a Player Object”. The confusing thing is that it fires the event the first time, but if I try to do it again, the error comes up even though it worked before?

Here is the script:

local debounce = false

script.Parent.Touched:connect(function(Part)
	if not debounce then
		
		debounce = true
		
		local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
		game.ReplicatedStorage.Dialogue.ShopKeeper1:FireClient(Player)
		
		wait(10)
		
		debounce = false
	end
end)

I have put a normal script under a part in workspace.

It is likely that the Part.Parent is not guaranteed a Character. Nor is Part guaranteed to be any body part. You have to use if statements to control whether Part.Parent is a model and that Player is not nil.

2 Likes

Replace:

local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
game.ReplicatedStorage.Dialogue.ShopKeeper1:FireClient(Player)
wait(10)
debounce = false

with

local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
if Player then
    game.ReplicatedStorage.Dialogue.ShopKeeper1:FireClient(Player)	
    wait(10)
end
debounce = false
2 Likes

This was the problem, I didnt check if the player existed. Thanks.