Wow I am happy to see what you work there, now the problem is that its laggy because it only runs on the server side.
Are you familiar with local script with remote event? With this you don’t have to worry with the lag performance that only runs on the server, you can use local script to fire the client event.
(The only issue here is that it can be used with exploiter who has the handle with the local script with the remote that is connected to the server, you can use sanity checks).
You have to create a Remote Event for this to work and put it inside the replicatedstorage.
The Local script should be put inside
the starterplayer > starterplayerscripts
--// Local Script
local TS = game:GetService("TweenService")
local Left = game.Workspace.["Left Curtain"]
local Right = game.Workspace.["Right Curtain"]
local cd = game.Workspace.["Your Click Detector"]
local tweenInfo = TweenInfo.new(
.7, -- You can adjust the time animation to your likings
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
--// It will show the tween from the client except the server
game.ReplicatedStorage:WaitForChild("RemoteEvent").OnClientEvent:Connect(function(part, goal)
local play1 = TS:Create(part, tweenInfo, goal)
play1:Play()
end)
--// With this parameter, it will call its CFrame Axis connected to serverscript
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireServer(Left, Left.CFrame, Right, Right.CFrame)
--// Server Script
local left = workspace:WaitForChild("Left")
local right = workspace:WaitForChild("Right")
local cd = game.Workspace.["Your Click Detector"]
local db = false -- Debounce
local newSize = Vector3.new(1, 14, 5) -- Shrink your curtain to what you want to open.
local oldSize = Vector3.new(1, 14, 16) -- I added this if you want to close the curtain
--// The OnServerEvent creates an event inside this function
game.ReplicatedStorage:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(plr, part, partCFrame, part1)
cd.MouseClick:Connect(function()
if db == false then
local Goleft = {
CFrame = left.CFrame * CFrame.new(0, 0, (newSize.Z - left.Size.Z)/2), -- Use (newSize.Z - left.Size.Z)/2 to change the size of curtain
Size = newSize
}
local Goright = {
CFrame = right.CFrame * CFrame.new(0, 0, (newSize.Z - right.Size.Z)/-2), -- I added -2 to keep it on the right direction.
Size = newSize
}
--// The FireAllClient runs to each client that's inside the game
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireAllClients(part, Goleft)
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireAllClients(part1, Goright)
cd.MaxActivationDistance = 0 --// Added MaxActivationDistance so it waits for the tween to complete.
print(1) -- Checks the the amount. If its greater than one then its spammable.
wait(3)
cd.MaxActivationDistance = 32
db = true
else
local leftclose = {
CFrame = left.CFrame * CFrame.new(0, 0, (oldSize.Z - left.Size.Z)/2), -- Use (newSize.Z - left.Size.Z)/2 to change the size of curtain
Size = oldSize
}
local rightclose = {
CFrame = right.CFrame * CFrame.new(0, 0, (oldSize.Z - right.Size.Z)/-2), -- I added -2 to keep it on the right direction.
Size = oldSize
}
--// The FireAllClient runs to each client that's inside the game
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireAllClients(part, leftclose)
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireAllClients(part1, rightclose)
db = nil
cd.MaxActivationDistance = 0 --// Added MaxActivationDistance so it waits for the tween to complete.
print(2) -- Checks the the amount. If its greater than one then its spammable.
wait(3)
cd.MaxActivationDistance = 32
db = false
end
end)
end)
I am not very effecient when it comes to coding with remote events but for this script that I made with debounce and tween, the animation and the function is smooth. Also the Tween doesn’t run on server but the server script runs the script only for all client inside the server.