o/
Im trying to make an elevator which tp the player. Cuz it’s a bit hard to explain, here you go :
Elevatorr.rbxl (98.6 KB)
when the player take “elevator” to “elevator2”, it works fine, but when he takes “elevator2” to “elevator”, it glitches and tp a lot of time the player to the “elevator2” and reopens it doors. Can you help me please?
@Black_Albi Ok, I made a new Script in the principal model:
I’ve totally changed your method and i wrote this:
local down = false
local TeleportPositionUp = script.Parent.Elevator.DetectionArea
local TeleportPositionDown = script.Parent.Elevator2.DetectionArea
local buttonInFirst = script.Parent.Elevator.Prox2.ProximityPrompt
local buttonInSecond = script.Parent.Elevator2.Prox2.ProximityPrompt
buttonInFirst.Triggered:Connect(function()
if down == false then
for _, players in pairs(game.Players:GetPlayers()) do
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionDown.CFrame
end
down = true
else
for _, players in pairs(game.Players:GetPlayers()) do
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
down = false
end
end)
buttonInSecond.Triggered:Connect(function()
if down == true then
for _, players in pairs(game.Players:GetPlayers()) do
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
down = false
else
for _, players in pairs(game.Players:GetPlayers()) do
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionDown.CFrame
end
down = true
end
end)
This is the teleportScript you can add the other functions (tween, sound, etc.)
NOTE: You’ve used in pairs(game.Players:GetPlayers())
so this will teleport everyone when a player press a button.
Don’t use game.Plsyers:GetChildren(), use game.Players:GetPlayers() instead.
That was in the original script so i’ve made only the most important changes.
You can still change it though? He wants help improving his code, so I’d you are going to provide fixed code, make it the best it can be. Go ahead and edit your post and replace it with GetPlayers(), so he can look at it for reference as he learns scripting. No need to argue with me.
Ok i’ve changed the script.
That was my opinion.
Well it is not recommended to use :GetChildren for players, in case you parent something else on the Plsyers service, but thanks for changing it.
EDIT: Actually, to move a character, don’t set the RootPart’s CFrame. Use Character:SetPrimaryPartCFrame(goalCFrame)
Using your method would destroy the player.
I tested it and it didn’t destroyed anything.
Incorrect. While :SetPrimaryPartCFrame()
is more ideal, setting the root part’s cframe does not destroy / kill the player. I have done this many times.
If it did, there would be no way at all to tween cframes of the player’s root part.
Ok sorry for the delay, I was in math lesson ^^'.
I tried your script and it works fine ! Thanks a lot.
Imma add the sound and all the others stuff.
You’re welcome! You can add the sound and the tween functions in the right points of the script.
It seems that when I teleport player who touch the detection area, it make a loop and tp them infinitly :
Here is the script :
local TeleportPositionUp = script.Parent.Elevator.DetectionArea
local TeleportPositionDown = script.Parent.Elevator2.DetectionArea
local buttonInFirst = script.Parent.Elevator.Prox2.ProximityPrompt
local buttonInSecond = script.Parent.Elevator2.Prox2.ProximityPrompt
local waitTime = 15
local down = true
-- If pos == true, then elevator is down, false means it is up
local goal = {}
local goal2 = {}
local goal3 = {}
local goal4 = {}
local goal5 = {}
local goal6 = {}
local goal7 = {}
local goal8 = {}
local TS = game:GetService("TweenService")
local part = script.Parent.Elevator.Door1
local part2 = script.Parent.Elevator.Door2
local part3 = script.Parent.Elevator2.Door1
local part4 = script.Parent.Elevator2.Door2
goal.Position = script.Parent.Elevator.Door1.Position -- Opened door 1
goal2.Position = script.Parent.Elevator.Door1.Position + Vector3.new(0,0,6.05) -- Closed door 1
goal3.Position = script.Parent.Elevator.Door2.Position -- Opened door 2
goal4.Position = script.Parent.Elevator.Door2.Position - Vector3.new(0,0,6.05) -- Closed door 2
-- Elevator 2
goal5.Position = script.Parent.Elevator2.Door1.Position + Vector3.new(0,0,6.05) -- Opened Door 1
goal6.Position = script.Parent.Elevator2.Door1.Position -- Close Door 1
goal7.Position = script.Parent.Elevator2.Door2.Position - Vector3.new(0,0,6.05) -- Open door 2
goal8.Position = script.Parent.Elevator2.Door2.Position -- Close Door 2
local tweenInfo = TweenInfo.new(3)
local tween = TS:Create(part, tweenInfo, goal)
local tween2 = TS:Create(part, tweenInfo, goal2)
local tween3 = TS:Create(part2, tweenInfo, goal3)
local tween4 = TS:Create(part2, tweenInfo, goal4)
local tween5 = TS:Create(part3, tweenInfo, goal5)
local tween6 = TS:Create(part3, tweenInfo, goal6)
local tween7 = TS:Create(part4, tweenInfo, goal7)
local tween8 = TS:Create(part4, tweenInfo, goal8)
local sound = script.Parent.ElevatorSound
buttonInFirst.Triggered:Connect(function()
if down == false then
sound:Play()
tween2:Play()
tween4:Play()
tween6:Play()
tween8:Play()
wait(waitTime)
script.Parent.Elevator.DetectionArea.Touched:Connect(function()
for _, players in pairs(game.Players:GetPlayers()) do
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionDown.CFrame
end
end)
down = true
tween:Play()
tween3:Play()
else
script.Parent.Elevator2.DetectionArea.Touched:Connect(function()
for _, players in pairs(game.Players:GetPlayers()) do
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
end)
tween:Play()
tween3:Play()
down = false
end
end)
buttonInSecond.Triggered:Connect(function()
sound:Play()
tween2:Play()
tween4:Play()
tween6:Play()
tween8:Play()
if down == true then
script.Parent.Elevator2.DetectionArea.Touched:Connect(function()
for _, players in pairs(game.Players:GetPlayers()) do
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
end)
tween5:Play()
tween7:Play()
down = false
else
script.Parent.Elevator2.DetectionArea.Touched:Connect(function()
for _, players in pairs(game.Players:GetPlayers()) do
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionDown.CFrame
end
end)
tween5:Play()
tween7:Play()
down = true
end
end)
Oh wait I maybe missplaced the function
Ok ye the problem was that I placed it outside this : for _, players in pairs(game.Players:GetPlayers()) do
I replaced it with :
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
end
Yep, now I just have to make the tween of the Up elevator (glitchy, it opens the doors of the down elevator instead of the up one) Thanks for your help
Theres just a weird thing with you script, this :
https://cdn.discordapp.com/attachments/782594725274189864/824694956949241936/Baseplate_-_Roblox_Studio_2021-03-25_18-22-47.mp4
When you click the button one time, it tp you to the down elevator, and then it plays correctly the animation, when your up, same thing, tp down then works fine
Sorry if i didn’t aswered but i got the post cooldown as a new member of the forum, anyways, can you show me the current script, so i can check if you missed something? Probably you missed a tween function in the first elevator.
I just want to specify that using in pairs(game.Players:GetPlayers())
all the players present in the server, even those who are in other areas of the map will be teleported and that would ruin the gaming experience. If you want to teleport only the player that trigger the proximityprompt you don’t need the for function you can just do this
buttonInFirst.Triggered:Connect(function(player)
player.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame --You can do this with TeleportPositionDown too
end)
I’m trying to teleport every players present in a zone, like a real elevaotr (except tp part), here is the current script :
local TeleportPositionUp = script.Parent.Elevator.DetectionArea
local TeleportPositionDown = script.Parent.Elevator2.DetectionArea
local buttonInFirst = script.Parent.Elevator.Prox2.ProximityPrompt
local buttonInSecond = script.Parent.Elevator2.Prox2.ProximityPrompt
local waitTime = 15
local down = true
local debounce = false
-- If pos == true, then elevator is down, false means it is up
local goal = {}
local goal2 = {}
local goal3 = {}
local goal4 = {}
local goal5 = {}
local goal6 = {}
local goal7 = {}
local goal8 = {}
local TS = game:GetService("TweenService")
local part = script.Parent.Elevator.Door1
local part2 = script.Parent.Elevator.Door2
local part3 = script.Parent.Elevator2.Door1
local part4 = script.Parent.Elevator2.Door2
goal.Position = script.Parent.Elevator.Door1.Position -- Opened door 1
goal2.Position = script.Parent.Elevator.Door1.Position + Vector3.new(0,0,6.05) -- Closed door 1
goal3.Position = script.Parent.Elevator.Door2.Position -- Opened door 2
goal4.Position = script.Parent.Elevator.Door2.Position - Vector3.new(0,0,6.05) -- Closed door 2
-- Elevator 2
goal5.Position = script.Parent.Elevator2.Door1.Position + Vector3.new(0,0,6.05) -- Opened Door 1
goal6.Position = script.Parent.Elevator2.Door1.Position -- Close Door 1
goal7.Position = script.Parent.Elevator2.Door2.Position - Vector3.new(0,0,6.05) -- Open door 2
goal8.Position = script.Parent.Elevator2.Door2.Position -- Close Door 2
local tweenInfo = TweenInfo.new(3)
local tween = TS:Create(part, tweenInfo, goal)
local tween2 = TS:Create(part, tweenInfo, goal2)
local tween3 = TS:Create(part2, tweenInfo, goal3)
local tween4 = TS:Create(part2, tweenInfo, goal4)
local tween5 = TS:Create(part3, tweenInfo, goal5)
local tween6 = TS:Create(part3, tweenInfo, goal6)
local tween7 = TS:Create(part4, tweenInfo, goal7)
local tween8 = TS:Create(part4, tweenInfo, goal8)
local soundDown = script.Parent.Elevator.Door1.ElevatorSound
local soundp = script.Parent.Elevator2.Door1.ElevatorSound
buttonInFirst.Triggered:Connect(function()
if debounce == false then
debounce = true
if down == false then
soundp:Play()
tween2:Play()
tween4:Play()
tween6:Play()
tween8:Play()
wait(waitTime)
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionDown.CFrame
end
end
tween5:Play()
tween7:Play()
down = true
else
soundDown:Play()
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
end
tween:Play()
tween3:Play()
down = false
end
debounce = false
end
end)
buttonInSecond.Triggered:Connect(function()
if debounce == false then
debounce = true
if down == true then
tween2:Play()
tween4:Play()
tween6:Play()
tween8:Play()
soundDown:Play()
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
end
tween5:Play()
tween7:Play()
down = false
else
soundp:Play()
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionDown.CFrame
end
end
tween:Play()
tween3:Play()
down = true
end
debounce = false
end
end)
script.Parent.Elevator2.Prox1.ProximityPrompt.Triggered:Connect(function()
if debounce == false then
debounce = true
if down == false then
soundp:Play()
tween2:Play()
tween4:Play()
tween6:Play()
tween8:Play()
wait(waitTime)
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator2.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionDown.CFrame
end
end
tween5:Play()
tween7:Play()
down = true
else
soundDown:Play()
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator2.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
end
tween:Play()
tween3:Play()
down = false
end
debounce = false
end
end)
script.Parent.Elevator2.Prox2.ProximityPrompt.Triggered:Connect(function()
if debounce == false then
debounce = true
if down == true then
tween2:Play()
tween4:Play()
tween6:Play()
tween8:Play()
soundDown:Play()
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator2.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionUp.CFrame
end
end
tween5:Play()
tween7:Play()
down = false
else
soundp:Play()
for _, players in pairs(game.Players:GetPlayers()) do
if script.Parent.Elevator2.DetectionArea.Touched then
players.Character:WaitForChild("HumanoidRootPart").CFrame = TeleportPositionDown.CFrame
end
end
tween:Play()
tween3:Play()
down = true
end
debounce = false
end
end)