#Detect where a tool collides with a part during animation

1 messages · Page 1 of 1 (latest)

lilac glade
#

I am working on a breakable system and I wanted particles when the tool collides with the breakable, but I've come to a roadblock with finding out where to put the particle emitter

If it is even possible, I would like for the hitPart particle emitter to be spawned in at the location of the tool colliding with the breakable.

So far, I've been unable to find a way to detect the collision

I tried connecting the touched event to a function but it would be generally unreliable and would fire even when just touching the breakable normally. Additionally, when trying to use a boolean it would clash with other tools in a weird way, breaking it.

Below is everything in the script I thought was relevant / needed. If anything else is needed or if I need to clarify something, let me know. This is my first time posting so I'm not very experienced lol.

--services and remotes

local tToolConfigs = {
    Axe = {
        BreakSound = "WoodChop",
        BreakTag = "WoodChop",
        ToolName = "Axe",
        DamageProp = "Axe.Damage",
        Animation = "http://www.roblox.com/asset/?id=77747786413711",
        HitPart = "TreeHit"
    },
    Pickaxe = {
        BreakSound = "RockBreak",
        BreakTag = "RockBreak",
        ToolName = "Pickaxe",
        DamageProp = "Pickaxe.Damage",
        Animation = "http://www.roblox.com/asset/?id=128853357",
        HitPart = "RockHit"
    }
}

local function playAnim(hum, Anim, tool, hitCFrame)
    local anim = Instance.new("Animation")
    anim.AnimationId = Anim
    local track = hum:LoadAnimation(anim)
    task.wait(0.5)
    track:Play()
    print("Axe Pos", tool:FindFirstChild("Axe").Position)
    print("Mouse Pos",hitCFrame.Position)
    
end

-- Other funcs...

remote.OnServerEvent:Connect(function(plr, sToolType, partHit, hitCFrame, iActive)
    local cfg = tToolConfigs[sToolType]
    if not cfg then return end

    local debounce = getDebounce(plr, "debounce_" .. sToolType)
    if debounce.Value or iActive == 0 then
        return
    end
    debounce.Value = true

    local success, err = pcall(function()
        local char = plr.Character
        if not char then return end

        local tool = char:FindFirstChild(cfg.ToolName)
        local hum = char:FindFirstChild("Humanoid")
        if not tool or not hum then return end
        

        local percentLeft = partHit:FindFirstChild("PercentLeft")
        local sound = partHit:FindFirstChild(cfg.BreakSound)
        if not percentLeft or not sound then return end

        local dmgVal = getDamageValue(tool, cfg.DamageProp)
        if not dmgVal then return end

        if hum:GetState() == Enum.HumanoidStateType.Jumping or hum:GetState() == Enum.HumanoidStateType.Freefall then
            return
        end
        
        local workPlayer = plr.Character
        for _, v in ipairs(workspace:GetChildren()) do
            if v:FindFirstChild("HumanoidRootPart") and v.Name == plr.Name then
                workPlayer = v.HumanoidRootPart
                break
            end
        end
        
        local isClose = (Vector3.new(workPlayer.Position.X, 0, workPlayer.Position.Z) - Vector3.new(partHit.Position.X, 0, partHit.Position.Z)).Magnitude <= 8
        if not isClose then return end
        
        local isHitting = plr.PlayerGui.DestroyObject.Frame.isHitting
        
        
        isHitting.Value = true
        playAnim(hum, cfg.Animation, tool, hitCFrame)
        task.wait(1)

        local hitPart = ReplicatedStorage:WaitForChild("BreakablesSystem"):WaitForChild(cfg.HitPart):Clone()
        hitPart.CFrame = hitCFrame
        hitPart.Parent = partHit
        task.delay(1, function() hitPart:Destroy() end)

        percentLeft.Value -= dmgVal.Value
        local percent = math.clamp(percentLeft.Value / 100, 0, 1)
        updateUI(plr, percent)

        sound:Play()
        if percentLeft.Value <= 0 then
            print("kil")
        end
        isHitting.Value = false
    end)

    debounce.Value = false
end)
raw juniper
#

what are you tying to do?, like particle will fire on the spot of where it collides?

#

To check collistion you could do sparil querying or raycast, usually should work

past portalBOT
#

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

raw juniper
#

and workPlayer, ehhh.. whats the reason for it

#

like workPlayer, i migth missed something but how do the isClose access ouside of its scoope, and look just look goofy, like it does nothing, like why would you loop thru the workspace and look for "humanoidroorpart"