bassicly the title
Using a LocalScript, you can do something like this:
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local Character = Players.LocalPlayer.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Door = workspace.Door -- Replace with the name of your door model/part
local ModelsTouched = 0
local Connection
local DoorOpenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, 0, false, 0)
local DoorOpenGoals = {CFrame = CFrame.Angles(0 ,1, 0)}
local DoorOpenTween = TweenService:Create{Door, DoorOpenInfo, DoorOpenGoals}
-- Replace with an animation if you prefer that rather than TweenService
local function GetTouchingParts()
for i, v in ipairs(workspace:GetTouchingParts(HumanoidRootPart)) do
if v:IsA("BasePart") and v.Parent.Name == ("TouchableModel") and v.Parent ~= Character and v.CanCollide then
ModelsTouched = ModelsTouched + 1
v.CanCollide = false
-- This is to prevent the player touching the same model multiple times
if ModelsTouched == 5 then
DoorOpenTween:Play()
end
Connection:Disconnect()
end
end
end
Connection = HumanoidRootPart.Touched:Connect(GetTouchingParts)
As long as you name the model âTouchableModelâ this will work - also should add that the HumanoidRootPart may not work in this case, using a different bodypart such as the head may be better.
I havenât tested this myself so if it throws any errors or doesnât work as you want it to, please say.
Hope this helps!
thx ill try that when i have time
Are you trying to make a door that only opens once each time the models are touched, or does it need to have a little bit of time when closing again, before you need to touch the models again?
it will stay open forever once you get all the models
were do i put the local script?
Put the LocalScript in StarterPlayer.StarterCharacterScripts
ill give you more context
im making a game kinda like mario 64 or odessey and i want to make a portal that teleports you to the second world but i want it so that you have to collect all of the start to open the portal
i already made the teleport script
Can you send the teleport script and where it is located in the explorer? The best way to do this is probably to integrate the two scripts somehow but I wonât know how without the script you wrote
local telePart = script.Parent
local TeleportService = game:GetService(âTeleportServiceâ)
local placeID = 8996667871
local canTeleport = true
local function otherGame(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player and canTeleport then
canTeleport = false
TeleportService:Teleport(placeID, player)
end
end
telePart.Touched:Connect(otherGame)
the script is located in the portal
idk why it only lua blocked a little bit lol
You can probably have the portal part behind the door and then when the door opens you can just walk into the portal, that is unless you want to teleport instantly
As a failsafe, you could put them in the same script and only set canTeleport as true when all 5 models are touched.
ok i dont know anything about coding lol but is it a problem that the portal is a mesh?
MeshParts behave physically the same as a Part, the only difference is that they can be given a MeshId which makes their appearance that of a 3D model (usually made in Blender). If you want to read more, itâs best to look at Robloxâs own documentation here.
tl:dr no, it doesnât matter
ok
i did make it in blender
Just checking, does everything work now? The door opens properly and doesnât give any errors? Just saying because, as mentioned before, I havenât actually tested that code myself.
one thing should i put both the teleport and the other script in the portal?
also what do i name the collectibles?
Put the teleport script under the portal and the door script in StarterCharacterScripts, alternatively you can combine them and put the singular script under StarterCharacterScripts. For simplicities sake, itâs probably easier to just do the first thing
Name the collectables TouchableModel in order to work with the script above, however you can name them whatever you want as long as you change the v.Parent.Name == ("TouchableModel")
to the name of the models.
and then do i name the portal door?