So I enabled StreamingEnabled on my game, and had to update all of my scripts to be on client side so that the parts that were scripted wouldn’t break themselves by unloading because of streaming enabled. Although I managed to fix most of my scripts, it seems that no matter what i do, i cannot for the life of me get the tweening of parts working.
What do I want to achieve?
Fix the door tweening in this script once and for all.
What is my issue?
The door open and close tween functions do not work, and frankly I have ran out of ideas on how to fix this.
What solutions have I tried so far?
- Remote event to fire function from client to server to all clients,
- Standard functions
sorry for the messy scripting, but the thing I’m trying to fix is the function named “OpenElevator” and “CloseElevator” and looking for possibly easier ways to do this type of stuff, since theres near to no documentation on how to clearly easily do this on roblox.
Anyway here is the local script that takes care of the elevator system:
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ElevatorEvents = ReplicatedStorage:WaitForChild("Elevator")
--//Events
local CloseElevatorEvent = ElevatorEvents:WaitForChild("CloseElevator")
local OpenElevatorEvent = ElevatorEvents:WaitForChild("OpenElevator")
local GoEvent = ElevatorEvents:WaitForChild("Go")
local OffClickDetectorEvent = ElevatorEvents:WaitForChild("OffClickDetector")
local OnClickDetectorEvent = ElevatorEvents:WaitForChild("OnClickDetector")
local PlayBellSFXEvent = ElevatorEvents:WaitForChild("PlayBellSFX")
local PlayElevatorAmbience = ElevatorEvents:WaitForChild("PlayElevatorAmbience")
local ChangeUpValue = ElevatorEvents:WaitForChild("ChangeUpValue")
local MovePlayer = ElevatorEvents:WaitForChild("MovePlayer")
--//Elevator Groups
local Elevators = game.Workspace:GetChildren()
for i, Elevator in pairs(Elevators) do
if Elevator.Name == "Elevators" then
local Elevator1 = Elevator:WaitForChild("Elevator1")
local Elevator2 = Elevator:WaitForChild("Elevator2")
--//Player Detectors
local Detector1 = Elevator1:WaitForChild("PlayerDetector")
local Detector2 = Elevator2:WaitForChild("PlayerDetector")
local Pos11 = Detector1.Position - (Detector1.Size/2)
local Pos12 = Detector1.Position + (Detector1.Size/2)
local Pos21 = Detector1.Position - (Detector1.Size/2)
local Pos22 = Detector1.Position + (Detector1.Size/2)
--//Doors 1
local Doors1 = Elevator1:WaitForChild("Doors")
local Door11 = Doors1:WaitForChild("Door1")
local Door12 = Doors1:WaitForChild("Door2")
--//Doors 2
local Doors2 = Elevator2:WaitForChild("Doors")
local Door21 = Doors2:WaitForChild("Door1")
local Door22 = Doors2:WaitForChild("Door2")
--//Panels
local Panel11 = Elevator1:WaitForChild("Panel1")
local Panel12 = Elevator1:WaitForChild("Panel2")
local Panel21 = Elevator2:WaitForChild("Panel1")
local Panel22 = Elevator2:WaitForChild("Panel2")
--//Buttons
local Button11 = Panel11:WaitForChild("Button")
local Button12 = Panel12:WaitForChild("Button")
local Button21 = Panel21:WaitForChild("Button")
local Button22 = Panel22:WaitForChild("Button")
--//Values
local UpValue = Elevator:WaitForChild("Up")
--//Infos
local DoorInfo = TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local SFXInf = TweenInfo.new(3)
--//Wait Settings
--DisableClickDetectors()
local W1 = 2
--CloseElevator()
local W2 = 4
--Go()
--UpValue.Value = true
local W3 = 32
--PlayBellSFX()
local W4 = 0.05
--OpenElevator()
local W5 = 3
--EnableClickDetectors()
--//Functions
ChangeUpValue.OnClientEvent:Connect(function(value)
UpValue.Value = value
end)
OffClickDetectorEvent.OnClientEvent:Connect(function()
Button11:WaitForChild("ClickDetector").MaxActivationDistance = 0
Button12:WaitForChild("ClickDetector").MaxActivationDistance = 0
Button21:WaitForChild("ClickDetector").MaxActivationDistance = 0
Button22:WaitForChild("ClickDetector").MaxActivationDistance = 0
end)
OnClickDetectorEvent.OnClientEvent:Connect(function()
Button11:WaitForChild("ClickDetector").MaxActivationDistance = 15
Button12:WaitForChild("ClickDetector").MaxActivationDistance = 15
Button21:WaitForChild("ClickDetector").MaxActivationDistance = 15
Button22:WaitForChild("ClickDetector").MaxActivationDistance = 15
end)
PlayBellSFXEvent.OnClientEvent:Connect(function()
if UpValue.Value == true then
Elevator2:WaitForChild("SoundPart"):WaitForChild("Bell"):Play()
else
Elevator1:WaitForChild("SoundPart"):WaitForChild("Bell"):Play()
end
end)
local function OpenElevator()
if UpValue.Value == false then
Door11:WaitForChild("DoorSFX"):Play()
Door12:WaitForChild("DoorSFX"):Play()
task.wait(1)
local OpenGoal1 = {}
OpenGoal1.CFrame = Door11.CFrame * CFrame.new(0, 0, 0)
TweenService:Create(Door11, DoorInfo, OpenGoal1)
local OpenGoal2 = {}
OpenGoal2.CFrame = Door12.CFrame * CFrame.new(0, 0, 0)
TweenService:Create(Door12, DoorInfo, OpenGoal2)
else
Door21:WaitForChild("DoorSFX"):Play()
Door22:WaitForChild("DoorSFX"):Play()
task.wait(1)
local OpenGoal1 = {}
OpenGoal1.CFrame = Door21.CFrame * CFrame.new(-3, 0, 0)
TweenService:Create(Door21, DoorInfo, OpenGoal1)
local OpenGoal2 = {}
OpenGoal2.CFrame = Door22.CFrame * CFrame.new(-3, 0, 0)
TweenService:Create(Door22, DoorInfo, OpenGoal2)
end
end
local function CloseElevator()
if UpValue.Value == false then
print(UpValue.Value)
Door11:WaitForChild("DoorSFX"):Play()
Door12:WaitForChild("DoorSFX"):Play()
task.wait(1)
local CloseGoal1 = {}
CloseGoal1.CFrame = Door11.CFrame * CFrame.new(-3, 0, 0)
TweenService:Create(Door11, DoorInfo, CloseGoal1)
local CloseGoal2 = {}
CloseGoal2.CFrame = Door12.CFrame * CFrame.new(-3, 0, 0)
TweenService:Create(Door12, DoorInfo, CloseGoal2)
else
print(UpValue.Value)
Door21:WaitForChild("DoorSFX"):Play()
Door22:WaitForChild("DoorSFX"):Play()
task.wait(1)
local CloseGoal1 = {}
CloseGoal1.CFrame = Door21.CFrame * CFrame.new(0, 0, 0)
TweenService:Create(Door21, DoorInfo, CloseGoal1)
local CloseGoal2 = {}
CloseGoal2.CFrame = Door22.CFrame * CFrame.new(0, 0, 0)
TweenService:Create(Door22, DoorInfo, CloseGoal2)
end
end
PlayElevatorAmbience.OnClientEvent:Connect(function(value)
local SFXGoalOn = {PlaybackSpeed = 1}
local SFXGoalOff = {PlaybackSpeed = 0}
print("got through")
if value == 2 then
TweenService:Create(Elevator2:WaitForChild("SoundPart"):WaitForChild("ElevatorMachineHum"), SFXInf, SFXGoalOn):Play()
TweenService:Create(Elevator2:WaitForChild("SoundPart"):WaitForChild("Music"), SFXInf, SFXGoalOn):Play()
task.wait(30)
TweenService:Create(Elevator2:WaitForChild("SoundPart"):WaitForChild("ElevatorMachineHum"), SFXInf, SFXGoalOff):Play()
TweenService:Create(Elevator2:WaitForChild("SoundPart"):WaitForChild("Music"), SFXInf, SFXGoalOff):Play()
elseif value == 1 then
TweenService:Create(Elevator1:WaitForChild("SoundPart"):WaitForChild("ElevatorMachineHum"), SFXInf, SFXGoalOn):Play()
TweenService:Create(Elevator1:WaitForChild("SoundPart"):WaitForChild("Music"), SFXInf, SFXGoalOn):Play()
task.wait(30)
TweenService:Create(Elevator1:WaitForChild("SoundPart"):WaitForChild("ElevatorMachineHum"), SFXInf, SFXGoalOff):Play()
TweenService:Create(Elevator1:WaitForChild("SoundPart"):WaitForChild("Music"), SFXInf, SFXGoalOff):Play()
end
end)
GoEvent.OnClientEvent:Connect(function()
if UpValue.Value == false then
OffClickDetectorEvent:FireServer()
task.wait(W1)
CloseElevator()
task.wait(W2)
local RegionDown = Region3.new(Pos11, Pos12)
local Parts = game.Workspace:FindPartsInRegion3(RegionDown, nil, math.huge)
for _, part in pairs(Parts) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
if part.Name == "HumanoidRootPart" then
local Char = part.Parent
local Player = Players:GetPlayerFromCharacter(Char)
local Root = part
local Offset = Root.Position - Detector1.Position
MovePlayer:FireServer(Player, Detector2.Position + Offset)
PlayElevatorAmbience:FireServer(Player, 2)
end
end
end
ChangeUpValue:FireServer(true)
task.wait(W3)
PlayBellSFXEvent:FireServer()
task.wait(W4)
OpenElevator()
task.wait(W5)
OnClickDetectorEvent:FireServer()
else
OffClickDetectorEvent:FireServer()
task.wait(W1)
CloseElevator()
task.wait(W2)
local RegionUp = Region3.new(Pos21, Pos22)
local Parts = game.Workspace:FindPartsInRegion3(RegionUp, nil, math.huge)
for _, part in pairs(Parts) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
if part.Name == "HumanoidRootPart" then
local Char = part.Parent
local Player = Players:GetPlayerFromCharacter(Char)
local Root = part
local Offset = Root.Position - Detector2.Position
MovePlayer:FireServer(Player, Detector1.Position + Offset)
PlayElevatorAmbience:FireServer(Player, 1)
end
end
end
ChangeUpValue:FireServer(false)
task.wait(W3)
PlayBellSFXEvent:FireServer()
task.wait(W4)
OpenElevator()
task.wait(W5)
OnClickDetectorEvent:FireServer()
end
end)
Button11.ClickDetector.MouseClick:Connect(function()
GoEvent:FireServer()
end)
Button12.ClickDetector.MouseClick:Connect(function()
GoEvent:FireServer()
end)
Button21.ClickDetector.MouseClick:Connect(function()
GoEvent:FireServer()
end)
Button22.ClickDetector.MouseClick:Connect(function()
GoEvent:FireServer()
end)
end
end
And here is the server script the remote events are being handled.
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayElevatorAmbience = ReplicatedStorage:WaitForChild("Elevator"):WaitForChild("PlayElevatorAmbience")
local Players = game:GetService("Players")
local ElevatorEvents = ReplicatedStorage:WaitForChild("Elevator")
--//Events
local CloseElevatorEvent = ElevatorEvents:WaitForChild("CloseElevator")
local OpenElevatorEvent = ElevatorEvents:WaitForChild("OpenElevator")
local GoEvent = ElevatorEvents:WaitForChild("Go")
local OffClickDetectorEvent = ElevatorEvents:WaitForChild("OffClickDetector")
local OnClickDetectorEvent = ElevatorEvents:WaitForChild("OnClickDetector")
local PlayBellSFXEvent = ElevatorEvents:WaitForChild("PlayBellSFX")
local PlayElevatorAmbience = ElevatorEvents:WaitForChild("PlayElevatorAmbience")
local ChangeUpValue = ElevatorEvents:WaitForChild("ChangeUpValue")
CloseElevatorEvent.OnServerEvent:Connect(function()
CloseElevatorEvent:FireAllClients()
end)
OpenElevatorEvent.OnServerEvent:Connect(function()
OpenElevatorEvent:FireAllClients()
end)
GoEvent.OnServerEvent:Connect(function()
GoEvent:FireAllClients()
end)
OffClickDetectorEvent.OnServerEvent:Connect(function()
OffClickDetectorEvent:FireAllClients()
end)
OnClickDetectorEvent.OnServerEvent:Connect(function()
OnClickDetectorEvent:FireAllClients()
end)
PlayBellSFXEvent.OnServerEvent:Connect(function()
PlayBellSFXEvent:FireAllClients()
end)
PlayElevatorAmbience.OnServerEvent:Connect(function(plr, plr2, Value)
PlayElevatorAmbience:FireClient(plr2, Value)
end)
ChangeUpValue.OnServerEvent:Connect(function(plr, Value)
ChangeUpValue:FireAllClients(Value)
end)
I genuinly am sick of having to spend SO long trying to bug fix this type of constant back and forth between server and client.
I wish there was a way to fire an event on all clients, from a client.