Hitbox script not working

I need the hitbox to appear after the value sets to true and everything works fine until the value doesn’t even set to true

this is the hitbox script

local punchevent = game.ReplicatedStorage.PunchEvent

wait(5)

game.Players.PlayerAdded:Connect(function(player)
	local character = player.Character
	local PlayerStatusValues = character.PlayerStatusData or character:WaitForChild("PlayerStatusData")
	if not PlayerStatusValues then
		return
	end
	local PunchingValue = PlayerStatusValues.PunchingValue or PlayerStatusValues:WaitForChild("PunchingValue")
	if not PunchingValue then
		return
	end
	while wait() do
	if PunchingValue == true then
	print("MB1TRIGGERED")
		local hitbox = Instance.new("Part")
		local weld = Instance.new("Weld")
		hitbox.Parent = character
		hitbox.Position = Vector3.new(character.position, character.position + 1, character.position -2.15)
		hitbox.Size = Vector3.new(4,3,2)
		hitbox.Anchored = true
		hitbox.CanCollide = false
		hitbox.Massless = true
		weld.Parent = character
		weld.Part0 = character.PrimaryPart
		weld.Part1 = hitbox
		wait(0.75)
		PunchingValue = false
		hitbox:Destroy()
		weld:Destroy()
	else
	 return
				
        end
	end
end)

this is the script that triggers M1 and it prints everything and completely works.

wait(5)

local player = game.Players.LocalPlayer

if not player then
	return
end
local character = player.Character or player.CharacterAdded:Wait()
if not character then
	return
end

local PlayerStatusValues = character.PlayerStatusData or character:WaitForChild("PlayerStatusData")
if not PlayerStatusValues then
	return
end

local PunchingValue = PlayerStatusValues:WaitForChild("PunchingValue") or PlayerStatusValues.PunchingValue
if not PunchingValue then
	return
end

local punchevent = game.ReplicatedStorage.PunchEvent
if not punchevent then
    return
end

local getmouse = player:GetMouse()

getmouse.Button1Down:Connect(function(TriggerEvent)
	print("MB1")
	PunchingValue = true
	print("PunchingValue = true")
	return
end)

if you could tell me if I did something wrong or need to know something about any other scripts feel free to do so.

1 Like

PunchingValue seems like an Instance while I guess you need a value so try:

while wait() do
	if PunchingValue.Value == true then
	print("MB1TRIGGERED")
		local hitbox = Instance.new("Part")
		local weld = Instance.new("Weld")
		hitbox.Parent = character
		hitbox.Position = Vector3.new(character.position, character.position + 1, character.position -2.15)
		hitbox.Size = Vector3.new(4,3,2)
		hitbox.Anchored = true
		hitbox.CanCollide = false
		hitbox.Massless = true
		weld.Parent = character
		weld.Part0 = character.PrimaryPart
		weld.Part1 = hitbox
		wait(0.75)
		PunchingValue = false
		hitbox:Destroy()
		weld:Destroy()
	else
	 return
				
        end
	end
getmouse.Button1Down:Connect(function(TriggerEvent)
	print("MB1")
	PunchingValue.Value = true
	print("PunchingValue = true")
	return
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.