Weird bug in my sword script

Hello, I have an issue with my sword script where every time i try to detect for a hitbox it will just say attempt to index nil with ‘Name’

Players.ozifawaz3050.Backpack.Bamboo Sword.Script:25: attempt to index nil with ‘Name’

Heres some code.

local user = script.Parent.Parent.Name

hitbox.Touched:Connect(function(obj)
		if obj.Parent.Name == user then
			--nocodehere
		else
			if obj.Parent:FindFirstChild("Humanoid") then
				obj.Parent.Humanoid:TakeDamage(2.5)
				script.SwordHit:Play()
				hitbox:Destroy()
			end
		end
	end)
end)
1 Like

I don’t know whattt ur doing but okay… do this

-- this is ugly don't do it >> local user = script.Parent.Parent.Name
local players_service = game:GetService('Players')

local local_player = players_service.LocalPlayer

local HUMANOID = local_player.Character.Humanoid or wait()

hitbox.Touched:Connect(function(object)
	HUMANOID:TakeDamage(2.5)
	script.SwordHit:Play()
	hitbox:Destroy()
end)

the script is server not local

send all the code ur just sending 1 bit

Wait for the weapon to be equiped, then set up the reference to the player’s name.