Variable not getting updated - Scripting

Hello! I am making a glove similar to Slap Battles and I cant seem to get this to work. The variable is printing Nil even though it is getting set.

local tool = script.Parent.Parent
local anim = script:WaitForChild("Slap")
local animTrack

local holdingPlr
local lastHitCharacter --THIS IS NOT CHANGING IN THE :Connect()

tool.Hitbox.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
	if plr ~= nil then
		lastHitCharacter = plr.Character
		--lastHitCharacter = plr.Character
		print("CLAP", plr.Character, lastHitCharacter) --PRINTS THE PLAYER CORRECTLY
	end
end)

game.ReplicatedStorage.Remotes.LocalPlayer_PressE.OnServerEvent:Connect(function(player)
	print("ok", lastHitCharacter)
	if player == holdingPlr then

		-- Teleport the player to the last hit character
		if lastHitCharacter ~= nil then
			print("Yippe")
            player.Character:SetPrimaryPartCFrame(lastHitCharacter.HumanoidRootPart.CFrame)
		else
			print("NO",lastHitCharacter) --PRINTS 'Nil'
		end
end)

lastHitCharacter is getting set but printing nil in the :Connect()
Thanks for any and all help! (Script is cut down to the simple parts)

Edit: My original comment was incorrect, so i removed it.

I think its because the remote event is firing before the hitbox is touched so therefore the variable has no value because it has not been previously set, returning nil.

But that’s the point of the script.

		if lastHitCharacter ~= nil then
			print("Yippe")
            player.Character:SetPrimaryPartCFrame(lastHitCharacter.HumanoidRootPart.CFrame)
		else -- if lastHitCharacter is nil then:
			print("NO",lastHitCharacter) --PRINTS 'Nil'
		end

If “lastHitCharacter” is not equal to nil then it’ll print Yippe, otherwise if it is nil it will print nil. So, what are you trying to do?

(by the way, if your making a slap battles game make it unique im getting tired of seeing this same thing)

I am trying to make this teleport to the last hit player. I’m setting lastHitCharacter in the collision function. but when ever it is in the :Connect() function, it returns it’s default value.
(I’ll try to make the game unique lol)

When you tested this, you first hit them then activated the ability, right?

yeah [[characterssssssss]]