What I want to achieve is making a door system like adopt me, if you get close to it the door opens for you and if you touch the neon white part your character will walk into the door en Teleport with a fading screen.
I’ve tried: Making a touch part which opens the door… And to move the player in the door I tried to use MoveToPoint. For the fading screen I tried tweening but that also failed as I am fairly new to tweening.
Thanks for reading! I don’t need full on scripts or anything but if you would like to I don’t mind!
You can use .Magnitude and tweenservice(put into starterGUI as local script)
local TS = game:GetService("TweenService")
local UI = --Reference the UI that you want to tween
local Tween = tween = TS:Create(UI, 3, {BackgroundTransparency = 1}, 1, true)
local Part = -- Reference the door
local HumanoidRootPart = game.Player.Character:WaitForChild("HumanoidRootPart")
while wait() do
if (door.Position - HumanoidRootPart.Position).Magnitude <= 10 then
--Door opens
else
--DoorCloses
end
Part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
-- teleport the player
end
end)
For me personally, I’d use :DistanceFromCharacter().
Actually, don’t do that, I just found a bug report explaing the issues with :DistanceFromCharacter() (Here), use Magnitude as @VegetationBush mentioned, but I improved upon it by using the :GetBoundingBox() method allowing to not rely on one singular static part.
I’d also recommend reading the resource by @colbert2677.
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Player")
local model = PathToModel -- use the resource i posted
local tween = tweenService:Create(...) -- add arguments
while wait(0.1) do
for _, player in ipairs(Players:GetPlayers()) do -- use ipairs because getplayers is an array, better performance in a loop.
if player.Character then
if (player.Character:GetBoundingBox().p - model:GetBoundingBox().p).Magnitude <= 10 then -- first argument of it is cframe, CFrame has the p field
tween:Play()
tween.Completed:Wait() -- wait for it to end before the next iteration
end
end
end
end
I made a system just like this not too long ago, if anyone would like to see or use the full source code you can download it here. (see my reply below)
This system is run completely on the client side, and the script is located under StarterPlayerScripts.
Hey… So this is hella cool! but one suggestion… Could you ever try making a way I could connect 2 rooms with a door? Basically cuz i made like a house with 2 rooms inside. OF course they are completely separated off each other and stuff, but i cant seem to find a way i can connect those 2 same rooms with a door in between them!
Nonetheless, the system is hella nice and resolved a lag issue big time!