I want someone’s opinion on my hitbox:
- When I run the function to create a hitbox I check if a player or an NPC is using the attack (if it’s a player then I run it on the client, if it’s an NPC I run it on the server)
- I heard running the hitboxes on the client makes it “smoother”
This is the code from the server:
local function hitbox(user, size, pos)
if game.Players:GetPlayerFromCharacter(user) then
local targets = hitboxFunc:InvokeClient(game.Players:GetPlayerFromCharacter(user), user, size, pos)
return targets
else
local cframe = user.HumanoidRootPart.CFrame * CFrame.new(pos)
local targets = game.Workspace:GetPartBoundsInBox(cframe, size)
local enemies = {}
for i, target in pairs(targets) do
if target.Name == "Hitbox" then
if target.Parent:FindFirstChild("Humanoid") then
if target.Parent.Name ~= user.Name then
table.insert(enemies, target.Parent)
end
end
end
end
return enemies
end
end
This is the code from the client:
local RS = game:GetService("ReplicatedStorage")
local hitboxFunc = RS.Events:WaitForChild("HitboxFunc")
hitboxFunc.OnClientInvoke:Connect(function(user, size, pos)
local cframe = user.HumanoidRootPart.CFrame * CFrame.new(pos)
local targets = game.Workspace:GetPartBoundsInBox(cframe, size)
local enemies = {}
for i, target in pairs(targets) do
if target.Name == "Hitbox" then
if target.Parent:FindFirstChild("Humanoid") then
if target.Parent.Name ~= user.Name then
table.insert(enemies, target.Parent)
end
end
end
end
return enemies
end)
Any suggestions? I’m still confused by the topic of running hitboxes on the client.