I am creating a hitbox that moves 100 studs in front of a player’s HumanoidRootPart and if this hitbox touches anything when it’s in motion, it will print the objects name.
I am using this in a server script and the Touched event doesn’t print anything if it comes into contact with an object…
local TweenService = game:GetService("TweenService")
local DebrisService = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerCommunication = ReplicatedStorage:WaitForChild("ServerCommunication")
local Hitbox = script.Hitbox
local Cooldown = 5
local Debounce = {}
local function RecieveSignal(Player)
if table.find(Debounce, Player.Name) then
print("Player is on a cooldown!")
else
local Character = Player.Character
local NewHitbox = Hitbox:Clone()
NewHitbox.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -4)
NewHitbox.Parent = workspace
DebrisService:AddItem(NewHitbox, 1)
TweenService:Create(
NewHitbox,
TweenInfo.new(1),
{Position = Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -100).Position}
):Play()
NewHitbox.Touched:Connect(function(Hit)
if not Hit:IsDescendantOf(Character) then
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
if Humanoid:FindFirstChild(Player.Name .. "HitboxCooldown") then
print("Player has already been damaged")
else
Humanoid:TakeDamage(5)
local HitboxCooldown = Instance.new("BoolValue")
HitboxCooldown.Name = Player.Name .. "HitboxCooldown"
HitboxCooldown.Parent = Humanoid
DebrisService:AddItem(HitboxCooldown, 3)
end
end
end
end)
table.insert(Debounce, Player.Name)
task.wait(Cooldown)
Debounce[table.find(Debounce, Player.Name)] = nil
end
end
ServerCommunication.OnServerEvent:Connect(RecieveSignal)
I honestly don’t know why this is happening, my best guess is the TweenService is stopping it from running, but I put the touched event in a thread and it still didn’t work.
The part’s properties:
