I have an elevator that tweens position back and forth, but when another player views a player in the elevator, their character reacts with the physics properly. But any other players they get whack and start going through the floor. Any ideas how to fix this?
Elevator script I made:
local main = script.Parent
local whichFloor = "lower"
local inRoute = false
local elevatorDingSound = script:WaitForChild("elevator ding")
local que = {
}
local part = script.Parent:WaitForChild("ElevatorMovingFloor")
-- Define the start and end positions
local startPos = Vector3.new(-639.23, 38.56, -212.49)
local endPos = Vector3.new(-639.23, 81.14, -212.49)
-- Define the duration of the tween in seconds
local tweenDuration = 5
-- Get the TweenService
local TweenService = game:GetService("TweenService")
-- Create a new tween
local tweenInfo = TweenInfo.new(tweenDuration)
local tween = TweenService:Create(part, tweenInfo, {Position = endPos})
-- Start the tween
local lowerButtonCall = main:WaitForChild("CallButtonsLower").Button
local upperButtonCall = main:WaitForChild("CallButtonsUpper").Button
local lowerDoors = main:WaitForChild("ElevatorDoorsLower")
local upperDoors = main:WaitForChild("ElevatorDoorsUpper")
local panelLowerButton = main:WaitForChild("ElevatorPanelFloor1")["2"].Button
local panelUpperButton = main:WaitForChild("ElevatorPanelFloor2")["1"].Button
lowerDoors.Parent = nil
lowerButtonCall.ClickDetector.MouseClick:Connect(function()
print("lower call button")
local tweenInfo = TweenInfo.new(tweenDuration)
local tween = TweenService:Create(part, tweenInfo, {Position = startPos})
-- Start the tween
if inRoute == false and whichFloor ~= "lower" then
inRoute = true
tween:Play()
upperDoors.Parent = workspace
end
tween.Completed:Connect(function()
inRoute = false
whichFloor = "lower"
lowerDoors.Parent = nil
elevatorDingSound:Play()
end)
end)
upperButtonCall.ClickDetector.MouseClick:Connect(function()
print("upper call button")
local tweenInfo = TweenInfo.new(tweenDuration)
local tween = TweenService:Create(part, tweenInfo, {Position = endPos})
-- Start the tween
if inRoute == false and whichFloor ~= "upper" then
inRoute = true
tween:Play()
lowerDoors.Parent = workspace
end
tween.Completed:Connect(function()
inRoute = false
whichFloor = "upper"
upperDoors.Parent = nil
elevatorDingSound:Play()
end)
end)
panelLowerButton.ClickDetector.MouseClick:Connect(function()
print("Going to upper floor")
local tweenInfo = TweenInfo.new(tweenDuration)
local tween = TweenService:Create(part, tweenInfo, {Position = endPos})
-- Start the tween
if inRoute == false and whichFloor ~= "upper" then
inRoute = true
tween:Play()
lowerDoors.Parent = workspace
end
tween.Completed:Connect(function()
inRoute = false
whichFloor = "upper"
upperDoors.Parent = nil
elevatorDingSound:Play()
end)
end)
panelUpperButton.ClickDetector.MouseClick:Connect(function()
print("Going to lower floor")
local tweenInfo = TweenInfo.new(tweenDuration)
local tween = TweenService:Create(part, tweenInfo, {Position = startPos})
-- Start the tween
if inRoute == false and whichFloor ~= "lower" then
inRoute = true
tween:Play()
upperDoors.Parent = workspace
end
tween.Completed:Connect(function()
inRoute = false
whichFloor = "lower"
lowerDoors.Parent = nil
elevatorDingSound:Play()
end)
end)