So the script works after I touch the part that pulls me to the black hole, but it doesn’t teleport me. There aren’t any errors I could find or see.
Edit: At first the script didn’t work, since I had to overwrite the orange lined scripts, now the second time I tried it worked, here the script:
local LocalPlayer = game.Players.LocalPlayer -- The local player.
local TeleportService = game:GetService("TeleportService")
repeat wait() until LocalPlayer and LocalPlayer:HasAppearanceLoaded() -- Waiting for the character to fully load to avoid "this part doesn't exist errors".
local Char = LocalPlayer.Character
local BlackholePart = game.Workspace.TheHole --Reference the part in the middle of the blackhole.
local ActivationPart = game.Workspace.TheActive --Reference the part that you step on to activate the blackhole.
local BlackholeActive = false -- Debounce
ActivationPart.Touched:Connect(function()
if BlackholeActive then return end -- Debounce
BlackholeActive = true
local bp = Instance.new("BodyPosition", Char.HumanoidRootPart)
bp.Position = BlackholePart.Position
bp.D = 1000 -- Adjust to your liking.
bp.MaxForce = Vector3.new(10000, 10000, 10000) -- Adjust to your liking
bp.P = 1000 -- Adjust to your liking
repeat wait(1) until (BlackholePart.Position - Char.HumanoidRootPart.Position).Magnitude < 2 -- Waits until the player is close enough to the center of the blackhole.
Char.HumanoidRootPart.CFrame = game.Workspace.ThePosition.CFrame -- Teleports the player.
end)
local bp = Instance.new(“BodyPosition”, Char.HumanoidRootPart)
I would advise against using the parenting feature upon creating an instance if you’re planning on changing the properties, it replicates on each property change where it would be more effective to have it replicate once.
local bp = Instance.new("BodyPosition")
-- All your property changes can go here before parenting bp to the desired parent.
bp.Parent = Char.HumanoidRootPart
It may also be worth mentioning that wait() is now deprecated, it would be better to use task.wait(num) when you wish to yield a thread for this scenario.
Also there is a much more effective way of avoiding the nil character error instead of this:
repeat wait() until LocalPlayer and LocalPlayer:HasAppearanceLoaded()
local Char = LocalPlayer.Character
This error is caused by the Character not loading in time. However, this can be fixed easily by doing:
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
Though I should also clarify, it is fine to use the parent argument while creating the instance if you do not desire to change the properties.
local sparkles = Instance.new("Sparkles", hrp)
Using Sparkles as an example as it was more likely to be used without properties needing to be changed, so because there’s no risk of multiple replications per property change; It’s fine to use the parenting argument when creating an instance.