Punching Script Breaks on Death

My punching script does not work after the player dies or resets. It uses region3. I send the player’s position but it does not update on the server.

Local Script:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")

local UIS = game:GetService("UserInputService")
local Enabled = true
local RE = script:WaitForChild("Function")


player.CharacterAdded:Connect(function (char)

	hrp = char:WaitForChild("HumanoidRootPart")
	print(hrp)
	

end)
UIS.InputBegan:Connect(function (input, GPE)
	
	if GPE then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if Enabled == true then
			RE:FireServer("Combat", hrp.CFrame * CFrame.new(0,0, -2.5).Position, char)
			print(hrp.CFrame * CFrame.new(0,0, -2.5).Position)
			Enabled = false
			wait(0.4)
			Enabled = true
		end
		
	end
end)

Server Script:
local RE = script.Parent
local Enabled = true
local combo = 1

RE.OnServerEvent:Connect(function(player, action, Pos)
	local char = player.Character or player.CharacterAdded:Wait()
	print(Pos)
	if Enabled == false then return end
	Enabled = false
	if action == "Combat" then
		if combo == 1 then
			combo = 2
			local Track = Instance.new("Animation")
			Track.AnimationId = "rbxassetid://7008354558"
			local Anim = char.Humanoid:LoadAnimation(Track)
			Anim:Play()
			local playingTracks = char.Humanoid.Animator:GetPlayingAnimationTracks()
			for i, v in pairs(playingTracks) do
				if v.Name == "walk" or v.Name == "run" then
					v:Destroy()
				end
			end
			
		elseif combo == 2 then
			combo = 1
			local Track = Instance.new("Animation")
			Track.AnimationId = "rbxassetid://7008358588"
			local Anim = char.Humanoid:LoadAnimation(Track)
			Anim:Play()
			local playingTracks = char.Humanoid.Animator:GetPlayingAnimationTracks()
			for i, v in pairs(playingTracks) do
				if v.Name == "walk" or v.Name == "run" then
					v:Destroy()
				end
			end
		end
		if char.Humanoid:FindFirstChild("Whoosh") then
			local whoosh = char.Humanoid:WaitForChild("Whoosh")
			whoosh:Play()
		else 
			local sound = Instance.new("Sound", char.Humanoid) 
			sound.Name = "Whoosh"
			sound.SoundId = "rbxassetid://231731980"
			sound.PlaybackSpeed = math.random(88, 120)/100
			sound:Play()
			
		end
		print("REGION")
		local HRP = char:WaitForChild("HumanoidRootPart")
		local RegionPart = game.ServerStorage.RegionPart:Clone()
		print("Cloned")
		RegionPart.Parent = workspace
		RegionPart.Position = Pos
		game.Debris:AddItem(RegionPart, 0.5)
	

			
			
		
	
		local region = Region3.new(Pos - (RegionPart.Size/2), Pos + (RegionPart.Size/2))
		local RTable = workspace:FindPartsInRegion3(region, RegionPart, 30)

		print(RTable)
		for i, v in pairs(RTable) do
			if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("Deb") == nil and v.Parent ~= char and v.Parent:FindFirstChild("Humanoid").Health ~= 0 then
				local Deb = Instance.new("BoolValue", v.Parent)
				Deb.Name = "Deb"
				game.Debris:AddItem(Deb, 0.4)
				local randomDMG = math.random(15,20)
				v.Parent.Humanoid:TakeDamage(randomDMG)
				print(randomDMG)
				
				if v:FindFirstChild("Punch") then
					local punch = v:WaitForChild("Punch")
					punch:Play()
				else 
					local s = Instance.new("Sound", v)
					s.Name = "Punch"
					s.SoundId = "rbxassetid://3932505023"
					s.PlaybackSpeed = math.random(88, 120)/100
					s:Play()
				end
				local attachment1 = Instance.new("Attachment", v.Parent:FindFirstChild("HumanoidRootPart"))
				local fx = game.ServerStorage:WaitForChild("FX")
				local punchFX = fx:WaitForChild("PUNCH")
				local random = math.random(0, 2)
				
				--if random == 1 then
					
				--	local particle = punchFX.Effects2:Clone()
					
				--	particle.Parent = attachment1
				--	particle:Emit(10)
				--	wait(0.2)
				--	particle:Destroy()
				--	print("ELLLO")
					
				--elseif random == 2 then
					
					local particle = punchFX.HitModuleParticle:Clone()
					particle.Parent = attachment1
					particle:Emit(10)
					wait(0.2)
					particle:Destroy()
					print("ELLO 2")
					
				--end
				
				if v.Parent.Humanoid.Health <= 25 then
					local Push = Instance.new("BodyVelocity", v.Parent:FindFirstChild("HumanoidRootPart"))
					Push.MaxForce = Vector3.new(1,0,1) * 20000
					Push.Velocity = char.HumanoidRootPart.CFrame.lookVector * 50
					game.Debris:AddItem(Push, 0.3)
				end
				
			end
			
		end
		
		Enabled = true
	end
	
end)

Please help. This is driving me insane.

Here’s a video of the incident:

Errors? Output? I don’t see anything wrong with it when I briefly read over it.

No errors just that the region spawns where the player last dies. I’ll try uploading a video. In the video before the player dies, the region spawns correctly in front of the player. After the player dies, the region spawns incorrectly and at the place of death.

Why not just put hrp.CFrame * CFrame.new(0,0, -2.5).Position in the server script? You should never really rely on the client for things that will need to be positioned, etc.

yea as he said exploiters can make global hits with this, I mean you can probably add a distance checker but that still aint it cause exploiters will still exploit that by doing sometypa auto aim when they’re near(Kill aura, 360 hitbox etc).

Where is the LocalScript located?
I suggest you put it in StartedPlayer.StarterCharacterScripts.
Or, better yet, adjust the script to not rely on respawning.
I think the behavior you’re currently getting is due to the “local char” being set, but never being reset whenever the player dies, this means that it’ll still be referencing to your last character.

Simply rerun the code after dying, or have it recognize the player’s death and adapt according to this.

By the way, hrp.CFrame * CFrame.new(0,0, -2.5).Position is wrong. You’re basically multiplying a CFrame with a Vector3. Maybe you meant (hrp.CFrame * CFrame.new(0, 0, -2.5)).Position. I tell you this because I use your same method but I use magnitude instead of Region3.

You update HRP when character gets added but your function parameter variable and the other char variable shares the same name.

I believe that CFrames can be multipled by Vector3’s.

Oh, didn’t know that. Thanks for telling me.

Thank you! The problem got solved when I put it into starter character scripts.