Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Homing Projectile keeps teleporting towards the victim's body when I want It to glide towards It (?)

Asked by 1 year ago

As the titles says, I made a tool that clones the handle, and what the cloned handle does Is that It will move In a straight line, If It touches someone, It will damage them to 1-5. And after a while It will home In towards the victim torso, dealing 10 damage. The problem Is that the homing projectile keeps teleporting towards the torso

Script:

local tool = script.Parent
local PathFinding = game:GetService("PathfindingService")

tool.RemoteEvent.OnServerEvent:Connect(function()
    local LAG_BALLTROLL = tool.Handle:Clone()
    tool.Handle.Transparency = 1
    tool.Handle.CanCollide = false
    LAG_BALLTROLL.Parent = game.Workspace
    LAG_BALLTROLL.Orientation = tool.Parent.Torso.Orientation
    LAG_BALLTROLL.Sounds.Ello:Play()
    LAG_BALLTROLL.Sounds.Ello.PlaybackSpeed = math.random(0.5,2)
    game:GetService("Debris"):AddItem(LAG_BALLTROLL,5)
    tool.Handle.Transparency = 1
    tool.Handle.CanCollide = false
    local HandleParts = tool.Handle:GetChildren()
    for _, Objects in ipairs(HandleParts) do
        if Objects:IsA("BasePart") then
            Objects.Transparency = 1
            Objects.CanCollide = false
        end
    end
    local Force = Instance.new("VectorForce",LAG_BALLTROLL)
    local Attachment2 = Instance.new("Attachment",LAG_BALLTROLL)
    Attachment2.Name = "YEETPOWERGOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"
    Force.Attachment0 = LAG_BALLTROLL.Attachment
    Force.Force = Vector3.new(0,0,-3000)
    Force.ApplyAtCenterOfMass = true
    game:GetService("Debris"):AddItem(Force,0.5)
    game:GetService("Debris"):AddItem(Attachment2,0.5)
    LAG_BALLTROLL.Touched:Connect(function(hit)
        local Humanoid = hit.Parent:WaitForChild("Humanoid")
        if Humanoid ~= tool.Parent.Humanoid then
            Humanoid:TakeDamage(math.random(1,5))
            LAG_BALLTROLL.Sounds.Ello:Stop()
            wait(1)
            local StopIt_GetSomeHelp = false
            while wait() do
                if not StopIt_GetSomeHelp then
                    StopIt_GetSomeHelp = true
                    local ZePath = PathFinding:CreatePath()
                    ZePath:ComputeAsync(LAG_BALLTROLL.Position, hit.Parent.Torso.Position)
                    if ZePath.Status == Enum.PathStatus.Success then
                        local Waypoints = ZePath:GetWaypoints()
                        for _, waypoint in pairs(Waypoints) do
                            local Position = Instance.new("Part",game.Workspace)
                            game:GetService("Debris"):AddItem(Position,5)
                            Position.Position = waypoint.Position
                            Position.Anchored = true
                            Position.Transparency = 1
                            Position.CanCollide = false
                            LAG_BALLTROLL.Position = waypoint.Position
                            LAG_BALLTROLL.Touched:Connect(function(hit)
                                if Humanoid ~= tool.Parent.Humanoid then
                                    StopIt_GetSomeHelp = false
                                    Humanoid:TakeDamage(10)
                                    game:GetService("Debris"):AddItem(Position,0)
                                    wait(2.3)
                                    StopIt_GetSomeHelp = true
                                end
                            end)
                            wait(0)
                        end
                    end
                end
            end
        end
    end)
    wait(0.5)
    for _, Objects in ipairs(HandleParts) do
        if Objects:IsA("BasePart") then
            Objects.Transparency = 0
            Objects.CanCollide = true
        end
    end
    tool.Handle.Transparency = 0
    tool.Handle.CanCollide = true
end)
1
Um what? pathfinding for a flying projectile? Puppynniko 1059 — 1y
0
Kinda, the ball moves In a straight line, and when It hits something, (I didn't add this effect cuz I don't know why) the ball looses Its anti-gravity effect, and after 1 second pathfind Its vicitim whom got hit, but I mean, I am Intrested In pathfinding flying projectiles imnotaguest1121 362 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

The reason why it follows the player's torso at all times and not just shoot at the old torso position is that you're getting the torso position inside the loop. Instead, define the torso outside the loop.

        local torso_pos = hit.Parent.Torso.Position
        while task.wait() do
            if not StopIt_GetSomeHelp then
                StopIt_GetSomeHelp = true
                local ZePath = PathFinding:CreatePath()
                ZePath:ComputeAsync(LAG_BALLTROLL.Position, torso_pos)
Ad

Answer this question