Hey, I’d like my sword to be destroyed upon contact with the hitbox, but strangely it’s not working, and when I added some print, nothing get printed.
remote.OnServerEvent:Connect(function(player, mousePosition)
local Ground = rs.Sol:Clone()
Ground.Position = Vector3.new(mousePosition.X, 2, mousePosition.Z)
Ground.Parent = SAV
local sword = rs.Sword:Clone()
sword.CFrame = CFrame.new(mousePosition.X, 500, mousePosition.Z) * CFrame.Angles(math.rad(90),0,0)
sword.Orientation = Vector3.new(90,0,0)
sword.CanCollide = true
sword.Anchored = true
sword.Parent = SAV
local hitbox = Instance.new("Part")
hitbox.Name = "hitbox"
hitbox.Size = Vector3.new(120, 20, 120)
hitbox.CanCollide = false
hitbox.CanTouch = true
hitbox.Anchored = true
hitbox.Transparency = 0
hitbox.CFrame = CFrame.new(Ground.Position.X, 2, Ground.Position.Z)
hitbox.Parent = SAV
sword.Touched:Connect(function(hit)
local parentName = hit.Parent.Name
if parentName == "hitbox" then
sword:Destroy()
end
end)
local newCFrame = CFrame.new(sword.Position.X, 0, sword.Position.Z) * CFrame.Angles(math.rad(90),0,0)
TS:Create(sword, TweenInfo.new(1, Enum.EasingStyle.Linear ,Enum.EasingDirection.Out), {CFrame = newCFrame}):Play()
end)