#ability system lag

1 messages · Page 1 of 1 (latest)

shadow badge
#

how do I fix that?
idk how to do lag compensation without teleporting
the red forcefield is hotbox
I need it to spawn in front of client (now it spawns in front of player from server's perspective)
hitbox function


-- Creates a visible hitbox part, calls onHit for each humanoid hit, then cleans up
function HitboxUtil.CreateHitbox(params)
    -- params: {CFrame, Size, Duration, Creator, OnHit}
    local part = Instance.new("Part")
    part.Anchored = true
    part.CanCollide = false
    part.CanQuery = false
    part.CanTouch = true
    part.Size = params.Size or Vector3.new(4,4,4)
    part.CFrame = params.CFrame
    part.Transparency = 0.3
    part.Color = Color3.fromRGB(255,0,0)
    part.Material = Enum.Material.ForceField
    part.Name = "AbilityHitbox"
    part.Parent = workspace

    local touched = {}
    part.Touched:Connect(function(hit)
        local humanoid = hit.Parent and hit.Parent:FindFirstChild("Humanoid")
        if humanoid and not touched[humanoid] and humanoid.Parent ~= params.Creator then
            touched[humanoid] = true
            if params.OnHit then
                params.OnHit(humanoid)
            end
        end
    end)

    task.delay(params.Duration or 0.2, function()
        if part then part:Destroy() end
    end)
    return part
end

return HitboxUtil

I tried adding location to that function but that didnt change anything
it used server location even tho I used remote events

#

part of character module

local Warrior = {}

Warrior.Abilities = {
    ["LeftClick"] = {
        Name = "Slash",
        Cooldown = 1,
        Activate = function(player, character)
            print("[Warrior] Slash ability triggered for", player and player.Name)
            if not character then
                warn("[Warrior] No character provided to Slash ability")
                return
            end
            local root = character:FindFirstChild("HumanoidRootPart")
            if not root then
                warn("[Warrior] No HumanoidRootPart found for Slash ability")
                return
            end
            local cframe = root.CFrame * CFrame.new(0, 0, -3)
            local hitbox = HitboxUtil.CreateHitbox{
                CFrame = cframe,
                Size = Vector3.new(5,5,5),
                Duration = 0.15,
                Creator = character,
                OnHit = function(humanoid)
                    print("[Warrior] Slash hit:", humanoid.Parent and humanoid.Parent.Name)
                    humanoid:TakeDamage(20)
                end
            }
            if not hitbox then
                warn("[Warrior] Slash hitbox was not created")
            end
        end
    },```
#

AbilityServerHandler

ivory wharfBOT
#

studio** You are now Level 1! **studio

shadow badge
#
local Players = game:GetService("Players")
local AbilityRequest = ReplicatedStorage:WaitForChild("AbilityRequest")
local CooldownUpdate = ReplicatedStorage:WaitForChild("CooldownUpdate")
local Classes = ReplicatedStorage:WaitForChild("Classes")

-- Leaderstats setup
Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local classStat = Instance.new("StringValue")
    classStat.Name = "Class"
    classStat.Value = "Warrior"
    classStat.Parent = leaderstats
end)

-- Cooldown tracking
local playerCooldowns = {}

local function getClassModule(className)
    local classFolder = Classes:FindFirstChild(className)
    if classFolder then
        local module = classFolder:FindFirstChild(className .. "ClassModule")
        if module and module:IsA("ModuleScript") then
            return require(module)
        end
    end
    return nil
end```
#
    local className = "Warrior"
    if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Class") then
        className = player.leaderstats.Class.Value
    end
    local classModule = getClassModule(className)
    if not classModule then return end

    local ability = classModule.Abilities[key]
    if not ability then return end

    playerCooldowns[player] = playerCooldowns[player] or {}
    local lastUsed = playerCooldowns[player][key] or 0
    if tick() - lastUsed < ability.Cooldown then
        -- Still on cooldown
        return
    end

    -- Ability logic
    local character = player.Character
    if character and ability.Activate then
        ability.Activate(player, character)
    end

    -- Set cooldown
    playerCooldowns[player][key] = tick()
    CooldownUpdate:FireClient(player, key, ability.Cooldown)
end)

Players.PlayerRemoving:Connect(function(player)
    playerCooldowns[player] = nil
end)
modern python
#

why do you need to fix this?

shadow badge
#

I kinda fixed it but there is a 1 tick delay

#

and idk is it possible to fix it

modern python
#

Predict position based on velocity, or just weld it to torso before activating the hitbox( check if a value is true before checking the hitbox)

#

2nd is prob easier