Need help with my hitbox script

I have been trying to fix this for 3 days now and it is making no sense. I have a hixbox put on each player at the start of the game. The hitbox has a script in it that can be run by setting the DamageIntake Bool value within the script to true which is detected by by a changed event.
I have also put a string value within the script that is called CurrentPlayer and has the name of the current model that the hitbox is inside. For some reason even though the currentPlayer value is set to the correct player(I checked them in a running 2 player game) , one player is able to hit the other but the second player cannot hit the first. I have printed the player names at the start of the script to ensure it is the right player but it still detects the wrong player when I say

game.Workspace:FindFirstChild(script.CurrentPlayer.Value).Humanoid.Health -= script.DamageAmount.Value

This makes no sense as it seems like the string value somehow has 2 values at once. I have check and changed the code over the last 3 days as much as possible with no luck. Someone save me please.

Here is the full code : `


--Welds the hitbox to the player
while true do
	wait()
	if script.Parent.Parent.Parent:FindFirstChild("Humanoid") then
		script.CurrentPlayer.Value = script.Parent.Parent.Parent.Name
		print(script.CurrentPlayer.Value)
		local rootPart = game.Workspace:FindFirstChild(script.CurrentPlayer.Value).HumanoidRootPart

		local weld = Instance.new("Weld",rootPart)
		weld.Part0 = rootPart
		weld.part1 = script.Parent
		weld.C1 *= CFrame.new(0,.5,0)
		break
	end
end

print(script.CurrentPlayer.Value.."again")

--Specifications
local IFramesTime = 0.1


--Character features
local hitBox = script.Parent
local damageIntake = script.hit
local event = game.ReplicatedStorage.RemoteEvents.BDD


--Character action states
local IsBlocking = false
local blockFrames = 0


--Asks client for character actions
damageIntake.Changed:Connect(function(change)
	print(script.Parent.Parent.Parent.Name.." script running")
	
	--Ensure the damage change is the player getting hit and not the IFrames vanishing
	if change == true then
		
		event:InvokeClient(game.Players:FindFirstChild(script.CurrentPlayer.Value),"Blocking")
	
	wait(0.1)
	damageIntake.Value = false
		
	end
	
end)


--Client returns values and the attack is run
event.OnServerInvoke = function(plr,value,blockTime,defenenceType)

	if defenenceType == "Blocking" then
		
		blockFrames = blockTime
		IsBlocking = value

	end
	
	if IsBlocking == false then
		task.wait()

		game.Workspace:FindFirstChild(script.CurrentPlayer.Value).Humanoid.Health -= script.DamageAmount.Value
		print(game.Workspace:FindFirstChild(script.CurrentPlayer.Value).Name.."got hit")
		
		if script.Ragdoll.Value == true then
			
			local ragdollScript  = require(game.ServerScriptService.ServerScripts.Ragdoll)
			script.Ragdoll.Value = false
			
			
			ragdollScript.Start(game.Workspace:FindFirstChild(script.CurrentPlayer.Value))
			
			wait(script.RagdollTime.Value)
			
			ragdollScript.Stop(game.Workspace:FindFirstChild(script.CurrentPlayer.Value),100,16)
			script.RagdollTime.Value = 0
			
			
		end
		
		if script.KnockBackPower.Value > 0 then
			
			local velocity = Instance.new("BodyVelocity",game.Workspace:FindFirstChild(script.CurrentPlayer.Value).HumanoidRootPart)
			velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			velocity.Velocity = game.Workspace:FindFirstChild(script.PlayerWhoHit.Value).HumanoidRootPart.CFrame.LookVector * script.KnockBackPower.Value
			wait(script.KnockBackTime.Value)
			velocity:Destroy()
			
		end
		
	end
	
end

1 Like

Here is a studio layout and the script that puts the hitboxes into the character as they join:

1 Like

First:

If the hitbox is inserted directly into the character then there is 1 too many Parent properties.

script.CurrentPlayer.Value = script.Parent.Parent.Name

Second, there are a ton of organizational issues in your code, which is likely why it is so hard to debug. I would recommend creating more variables, as you set a lot of things equal to the same thing over and over again.

I will keep playing around with the script to see if I can get the system to give me the same issue, however, I just wanted to make sure that the hitbox is getting put in the right spot before I continue.

Thanks a lot! I will try organise it more but I still really need help with this problem . Thanks for taking time out your day :pray:

1 Like

Right, so is the hitbox inserted directly into the character or somewhere else in the character?

It is in a folder within the character called Hitboxes, it is stored there along with output hitboxes for M1s and other moves.

1 Like

If you want to activate it without the need for a m1 system you can just set the damage number and set the hit bool value to true.

Also the reason it is so disorganised is because I thought if i used a string value for the character instead of getting a variable for it with script.Parent.Parent.Parent maybe it would work. So i do plan on changing that back if it has no effect on the issue.