I want to make a hitbox that moves along with the player and at the same time be able determine the position its separated from the player, i cant find a solution. Ive tried welding it with this piece of code
Hitbox.CFrame = CharacterWhoKicked.HumanoidRootPart.CFrame * CFrame.new(1,-1.3 ((Hitbox.Size.Z/2) + 0.5 ) * -1)
but it doesnt matter if you asign a position its gonna stuck to the player, and ive also tried changing the position of the hitbox every frame but it lags behind the player what can i do now
please helpppppppppppppp
here is the whole server script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Kick = ReplicatedStorage.Kick
local RunService = game:GetService("RunService")
local KickAnimation = script.Parent.KickAnim
local Strenght = 1000
function ReadTable(table_)
warn("-----------------")
for i,v in pairs(table_) do
print(v)
end
warn("-----------------")
end
function FindPlayer(Chrt)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name == Chrt.Name then
return v
end
end
end
--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--
----__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__--__----
function AddPlayersToTable(PartsInsideHitbox, HumanoidsKicked, PlayerKicking)
-- If there is a part by a character is added on the table
-- so we can't push the same player twice
-- (multiple parts of the same character can be kicked and its gonna apply more impulse than it should)
for index,part in pairs(PartsInsideHitbox) do
if part.Parent:FindFirstChild("Humanoid") and PlayerKicking.Name ~= part.Parent.Name then
if table.find(HumanoidsKicked, part.Parent) then
-- Player already in table
else
table.insert(HumanoidsKicked, part.Parent)
-- Player Added
end
end
end
end
function Impulse(Part, CharacterWhoKicked)
if FindPlayer(Part.Parent) then --//--// IF ITS A PLAYER
Kick:FireClient(FindPlayer(Part.Parent), CharacterWhoKicked, Strenght)
warn("its a player")
return
end
local dir = CharacterWhoKicked.HumanoidRootPart.CFrame.LookVector * Strenght
Part:ApplyImpulse(dir)
end
Kick.OnServerEvent:Connect(function(Player)
local CharacterWhoKicked = Player.Character
--//--//-- Checking the player is alive
if CharacterWhoKicked.Humanoid and CharacterWhoKicked.HumanoidRootPart then
local HumanoidWhoKicked = CharacterWhoKicked.Humanoid
local Track = HumanoidWhoKicked:LoadAnimation(KickAnimation)
Track:Play()
--//--//-- Playing Animation (Animation has Marker called hit)
--//--//-- maybe i'll use it later (prob not)
--//--//--Track:GetMarkerReachedSignal("hit"):Connect(function()
local Hitbox = Instance.new("Part")
Hitbox.Anchored = true
Hitbox.CanCollide = false
Hitbox.Massless = true
Hitbox.Name = "Hitbox"
Hitbox.Size = Vector3.new(1,1,1.5)
Hitbox.Transparency = 0.5
Hitbox.Parent = CharacterWhoKicked["Right Leg"]
local PartsInsideHitbox = workspace:GetPartsInPart(Hitbox)
local HumanoidsKicked = {}
AddPlayersToTable(PartsInsideHitbox, HumanoidsKicked, CharacterWhoKicked)
--ReadTable(HumanoidsKicked)
--ReadTable(PartsInsideHitbox)
local function HitboxDetector(part, index)
if part.Parent:FindFirstChild("Humanoid") then --//--// ITS A PLAYER
if table.find(HumanoidsKicked, part.Parent) ~= nil then
table.remove(HumanoidsKicked, table.find(HumanoidsKicked, part.Parent))
warn("Apply Impulse to Humanoid ".. part.Parent.Name)
Impulse(part, CharacterWhoKicked)
end
else --//--// ITS A BRICK
if part.Anchored == false then
warn("Apply Impulse to Regular Part "..part.Name)
Impulse(part, CharacterWhoKicked)
end
end
end
for index,part in pairs(PartsInsideHitbox) do --//--//-- this loops trough all the parts
HitboxDetector(part, index)
end
wait(1)
Hitbox:Destroy() --yikes
end
end)