I have created a door which detects for player input on the server and then fires all clients to then initiate the door tweening. By doing this it will make the door move smoothly on any laggy clients opening the door.
I have came across a problem. The problem is that sometimes after a player requests to open the door, the door rotation will make the door close and open at incorrect angles. I think it has to do with client lag from the client, when the server is telling the client to tween the door, when the door hasn’t shut yet on the client.
Server script:
for i,v in pairs(Door:GetChildren())do
if v:FindFirstChild("ProximityPrompt") then
v.ProximityPrompt.Triggered:Connect(function(Player)
if Toggle == false then
Toggle = true
if v.ProximityPrompt.Value.Value == "Left" then
Rotation = -100
else
Rotation = 100
end
game.ReplicatedStorage.Remotes.DoorEvent:FireAllClients(DoorPrimary, Rotation)
wait(6)
Toggle = false
end
end)
end
end
end
Client script:
local TweenService = game:GetService("TweenService")
game.ReplicatedStorage.Remotes.DoorEvent.OnClientEvent:Connect(function(DoorPrimary, Rotation)
TweenService:Create(DoorPrimary, TweenInfo.new(), {CFrame = DoorPrimary.CFrame * CFrame.Angles(0,math.rad(Rotation),0)}):Play()
wait(5)
TweenService:Create(DoorPrimary, TweenInfo.new(), {CFrame = DoorPrimary.CFrame * CFrame.Angles(0,math.rad(-Rotation),0)}):Play()
end)
Another question I had is about the possible exploits of the door, the tween is done on the client which means they could exploit it, but I’m not sure this would matter anyway because the client can easily abuse the Can-Collide property to walk through the door anyway. Any help or suggestions would be appreciated.