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

BodyPosition and RocketProplusion both glitching? Is there any possible way to fix?

Asked by 3 years ago

So I recently learned about magnitude and distance. I made a part (or more specifically an egg) to test it out. Heres the code below:

local dsi = 50



game.Players.PlayerAdded:Connect(function(plate)
    plate.CharacterAdded:Connect(function(charac)


        local function chase()
            local bp = Instance.new("BodyPosition")
            bp.Parent = script.Parent
            local torso = charac.Torso

            bp.Position = torso.Position
            script.Parent.Claws.Transparency = 0
            script.Parent.Claws.Script.Disabled = false

        end



        while true do
            wait(0.3)
            local plsr= game.Players:GetChildren()
            for i, play in pairs(plsr) do
                if play.Character ~= nil then
                    local leg =    play.Character["Left Leg"]
                    local dis = (script.Parent.Position - leg.Position).magnitude
                    local distance = math.floor(dis)


                    if distance <= (dsi) then
                        wait(1)
                        script.Parent.Script.Disabled = true
                        chase()
                        wait(0.7)
                        local bp = script.Parent:FindFirstChild("BodyPosition")
                        if bp then
                            bp:Destroy()
                        end
                        if not bp then
                            wait(1)
                        end


                    else if distance > (dsi) then
                            script.Parent.Claws.Transparency = 1
                            script.Parent.Claws.Script.Disabled = true
                            wait(0.4)
                            script.Parent.Script.Disabled = false
                            local bp = script.Parent:FindFirstChild("BodyPosition")
                            if bp then
                                bp:Destroy()
                            end
                            if not bp then
                                wait(1)
                            end

                        end
                    end

                end
            end
        end

    end)

end)

It may look a bit messy, but the code above works as expected. The only problem is after a player dies. The part will try to go to where the player died and the player's position at the same time. Causing it to glitch. Is there any way to fix or prevent this? Could it be that using bodymovers for this was a bad idea?

0
You see, if you set the MaxForce/P too high or D too low, that usually happens. There is no way (that I know of) of fixing it other than manually adjusting it until it becomes reasonably unglitchy. RAFA1608 543 — 3y
0
Hold on, my comment above might be irrelevant. Does the bodymovers get created more than once, and then forgotten about, causing it to glitch? RAFA1608 543 — 3y
0
due to the fact that there are two of them arguing who should be where? RAFA1608 543 — 3y
0
God, I am bad at interpreting things I read. Anyhow, your issue might be the fact that two bodymovers exists as opposed to only one. RAFA1608 543 — 3y
View all comments (3 more)
0
I see what you mean, both sound pretty reasonable. I could probably just be creating more than one bodyposition and the script isnt deleting it in time. Or i might need to fix the properties, i'll check it out tomorrow yayimstrongforever 0 — 3y
0
Its only one bodyposition thats functioning, any other leftover/duplicate bodyposition quickly gets deleted yayimstrongforever 0 — 3y
0
I just found out something weird, everytime the player dies. The script runs more than once, so if i had like something like a cannon shooting a cannonball and the player died somehow. Then it would have the same problem mentioned above except now it will shoot two cannonballs instead of one. If the player died a third time, it would now shoot 3 cannon balls that would go to different positions  yayimstrongforever 0 — 3y

Answer this question