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?