So I’ve created a basic skill with a hitbox, but it seems like the part is delayed from the hitbox. Should I try using coroutine for this? Any advice or tips would be appreciated
Heres a video:
The red is the hitbox and the gray is the part.
local script
local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local debris = game:GetService("Debris")
local runService = game:GetService("RunService")
local hitboxModule = require(replicatedStorage:WaitForChild("HitboxModule"))
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
local remoteEvent1 = replicatedStorage:WaitForChild("RemoteEvent1")
local part = replicatedStorage:WaitForChild("Part")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
tool.Activated:Connect(function()
local mouseHit = mouse.Hit
local hrp = player.Character.HumanoidRootPart
local clonePart = part:Clone()
clonePart.CFrame = hrp.CFrame
clonePart.Transparency = 1
debris:AddItem(clonePart, 10)
remoteEvent1:FireServer(mouseHit)
local params = OverlapParams.new()
params.FilterDescendantsInstances = {player.Character}
params.FilterType = Enum.RaycastFilterType.Blacklist
local hitbox = hitboxModule.createBox()
hitbox.Shape = Enum.PartType.Ball
hitbox.Size = 4
hitbox.OverlapParams = params
hitbox.CFrame = clonePart
local setAngle = clonePart.CFrame.Rotation
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local goal = {CFrame = CFrame.new(mouseHit.Position) * setAngle}
local tween = tweenService:Create(clonePart, tweenInfo, goal)
tween:Play()
hitbox:Play()
hitbox.Touched:Connect(function(hit, hum)
if hit and hum then
remoteEvent:FireServer(hit, hum, mouseHit)
end
end)
clonePart.Parent = workspace
end)
remoteEvent1.OnClientEvent:Connect(function(player, mouseHit)
local hrp = player.Character.HumanoidRootPart
local clonePart = part:Clone()
clonePart.CFrame = hrp.CFrame
debris:AddItem(clonePart, 10)
local setAngle = clonePart.CFrame.Rotation
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local goal = {CFrame = CFrame.new(mouseHit.Position) * setAngle}
local tween = tweenService:Create(clonePart, tweenInfo, goal)
tween:Play()
clonePart.Parent = workspace
end)
server script
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
local remoteEvent1 = replicatedStorage:WaitForChild("RemoteEvent1")
remoteEvent.OnServerEvent:Connect(function(player, hit, hum)
hum:TakeDamage(10)
end)
remoteEvent1.OnServerEvent:Connect(function(player, mouseHit)
remoteEvent1:FireAllClients(player, mouseHit)
end)