Hello fellow deform users! It seems my hitbox is not being created when an event fires.
local script:
local db = false
local count = 0
script.Parent.Activated:Connect(function()
if db == true then return end
if db == false and count == 0 then
db = true
game.ReplicatedStorage.HitBoxEvents.HitBoxEvent:FireServer()
script.Parent.Woosh:Play()
local Anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash1)
Anim:Play()
wait(1)
db = false
count += 1
end
end)
script.Parent.Activated:Connect(function()
if db == true then return end
if db == false and count == 1 then
db = true
game.ReplicatedStorage.HitBoxEvents.HitBoxEvent:FireServer()
script.Parent.Woosh:Play()
local Anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash2)
Anim:Play()
wait(1.5)
db = false
count = 0
end
end)
server script:
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local db = false
local plrs = game:GetService("Players")
local plr = plrs:GetPlayers()[1] or plrs.PlayerAdded:Wait()
local touched = false
local slash = script.Parent.Slash
script.Parent.HitBoxEvent.OnServerEvent:Connect(function()
if db then return end
db = true
local Hitbox = Instance.new("Part")
Hitbox.Parent = workspace
Hitbox.CFrame = workspace.QUESTS.Torso.CFrame
Hitbox.Transparency = 0.4
Hitbox.Anchored = true
Hitbox.Size = Vector3.new(7, 7, 5)
Hitbox.CanCollide = false
local HitChar = {}
-- we use here task.spawn to run the check in a separate thread
task.spawn(function()
for i = 0, 10 do -- Check 10 times (you can adjust this number depends on what you want)
local parts = workspace:GetPartsInPart(Hitbox)
for _, part in ipairs(parts) do
local character = part:FindFirstAncestorOfClass("Model")
if character and character:FindFirstChild("NPC") and not table.find(HitChar, character) and not touched then
touched = true
table.insert(HitChar, character)
print("Hit character:", character.Name)
end
end
task.wait(0.1) -- Wait 0.1 seconds between each check
end
game.Debris:AddItem(Hitbox, .2)
end)
task.wait(1)
touched = false
db = false
end)
all help is appreciated!