Black hole pullscript should slowly pull player

I made a black hole and have this script which sucks the player into the center once it touches this part, Thought I think it would be more realistic if it pulls more and more the closer you go to the black hole.

So just a small noticeable pull really far and when you’re closer it eventually pulls you in completely

function onTouched(hit)



bp = Instance.new("BodyPosition")
bp.Parent = hit
bp.maxForce = Vector3.new(4e+009, 4e+009, 4e+009)
bp.position = script.Parent.Position



end







connection = script.Parent.Touched:connect(onTouched)




Maybe use tweenservice instead.

how do i go about doing that ?

Using magnitude, if the humanoidrootpart gets in a certain distance to the blackhole, tween the HRP to the blackhole.

Im sorry, my scripting is limited can you help

Tweening is probably easiest, however for your script, you could get the distance away the player is, then times the values in the BodyPosition for the max force by 1/distance (so that it is more intense closer)

local MaxDistance = 1000
local Force = 10000
local CutoffDistance = 30

script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not Player then return end
	local Character = hit.Parent
	local Root = Character:FindFirstChild("HumanoidRootPart")
	if not Root then return end
	if Root:FindFirstChild("BlackholeForce") ~= nil then return end
	local Distance = math.clamp((Root.Position - script.Parent.Position).Magnitude, 0, MaxDistance)
	local BlackholeForce = Instance.new("BodyPosition")
	BlackholeForce.Name = "BlackholeForce"
	BlackholeForce.maxForce = Vector3.new(1, 1, 1) * (((MaxDistance-Distance)/MaxDistance) * Force)
	BlackholeForce.Position = script.Parent.Position
	BlackholeForce.Parent = Root
	repeat
		Distance = math.clamp((Root.Position - script.Parent.Position).Magnitude, 0, MaxDistance)
		BlackholeForce.maxForce = Vector3.new(1, 1, 1) * (((MaxDistance-Distance)/MaxDistance) * Force)
		wait()
	until
		Distance < CutoffDistance or Distance > MaxDistance or not Root
	BlackholeForce:Destroy()
end)
5 Likes

Hey, This script works but not correctly, it pulls the player when they touch the object and stops pulling at the middle, then eventually pulls again

https://gyazo.com/eb61d8a43c93159273d5e401c6b40d8e

I made it like that on purpose

just set cutoff distance to -1 or remove it and its check entirely

i did and now it stops sucking at the middle even if you die, and it pulls you in once you touch the part, not slowly

Could be your MaxDistance, CutoffDistance or Force

just mess around with the variables

you can add a print onto the .maxForce to see what youre getting
maybe a print to see when it exits the repeat loop

I believe the script is fine and you just need to tune it to your needs

If your touchpart is a cube I would do (script.Parent.Size.X*.6) for max distance

1 Like

the part is a cylinder actually