So, I’m using TweenService for a door that I’m making. Inside the door, there are two hinges, which are the objects being controlled by TweenService and rotated. Each hinge is attached to one side of the door, the left and the right. Originally, I had been tweening it on the server, however, I noticed that the faster you try to make the door, the more choppy, unrealistic, and messy it would look. Therefore, I moved it to the client controlled by a remote event.
The only problem with this is that when the door is open on everyone’s client, when a new player joins, the door appears closed for them. I’ve experimented with game.Players.PlayerAdded on the client and seeing if it was opened already, and then opening it for them if it’s closed on their client, but nothing like that seems to be working very well, and ends up breaking.
If there are any better solutions, please let me know! Would be greatly appreciated.
Server-Side Script
local status = closed
script.Parent.Clicker.MouseClick:Connect(function(plr)
if plr:GetRankInGroup(5033680) >= 25 then
if status == "closed" then
game.ReplicatedStorage.open:FireAllClients("open")
status = "open"
iconopen()
elseif status == "open" then
game.ReplicatedStorage.open:FireAllClients("close")
status = "closed"
iconclose()
end
end
end)
Client-Side Script
local TS = game:GetService("TweenService")
local hinge = game.Workspace.StaffDoors1.StaffAccessDoor.StaffDoor.Door.Hinge
local hinge2 = game.Workspace.StaffDoors1.StaffAccessDoor2.StaffDoor.Door.Hinge
local cf = Instance.new("CFrameValue")
cf.Value = hinge.CFrame
cf.Changed:Connect(function()
hinge.CFrame = cf.Value
end)
local cf2 = Instance.new("CFrameValue")
cf2.Value = hinge2.CFrame
cf2.Changed:Connect(function()
hinge2.CFrame = cf2.Value
end)
local waittime = 0.5
local status = "closed"
game.ReplicatedStorage.open.OnClientEvent:Connect(function(action)
if action == "open" then
status = "open"
print("open")
TS:Create(cf, TweenInfo.new(waittime), {Value = hinge.CFrame * CFrame.Angles(math.rad(0), math.rad(95), math.rad(0))}):Play()
TS:Create(cf2, TweenInfo.new(waittime), {Value = hinge2.CFrame * CFrame.Angles(math.rad(0), math.rad(-95), math.rad(0))}):Play()
elseif action == "close" then
status = "closed"
print("close")
TS:Create(cf, TweenInfo.new(waittime), {Value = hinge.CFrame * CFrame.Angles(math.rad(0), math.rad(-95), math.rad(0))}):Play()
TS:Create(cf2, TweenInfo.new(waittime), {Value = hinge2.CFrame * CFrame.Angles(math.rad(0), math.rad(95), math.rad(0))}):Play()
end
end)