Help with Box Script

Hello, devs! I am having a bit of an issue with writing a script. What this script does is
sends a remote event to the client for it to check if an animation is playing. It works, but whenever I do it, it keeps saying FireClient: player argument must be a Player object. Here is my script. Thanks for reading!

    local debounce = false

local box = game.Workspace.Box

script.Parent.Touched:Connect(function(hit)
	if debounce == false then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		game.ReplicatedStorage.CheckAnimation:FireClient(plr)
		debounce = true
		wait(3)
		debounce = false
	end
	if debounce == true then
		print("Player is spamming!")
	end
end)

game.ReplicatedStorage.DestroyBox.OnServerEvent:Connect(function(player)
	for i, v in pairs(box:GetDescendants()) do
		if v.Name == "Part" then
			v.Anchored = false
			v.CanCollide = false
		end
		if v.Name == "Part" and v:GetDescendants("SelectionBox") then
	        v:Destroy()
		end
	end
end)

FireClient: player argument must be a Player object means that the Player you passed in FireClient is not a player or is nil.

The variable plr might be nil, thus you are sending a nil value in ``FireClient`, which leads to the error.

Check if the plr variable is not nil.

1 Like

I printed the plr variable. At first, it said it’s nil then it said my username. I’m confused on why it didn’t pick me up on first touch.

Then it is likely that the plr variable will become nil. You can add a check if see if the plr variable is not equal to nil.

Ok, I’ll try that! Thank you for the help!

It’s fixed! I added a little check for it. Thanks for your help!