So I’m trying to script a button prompted door that allows the player to open doors which physically swings open from a local script to the server script via a remote event. However, the door kept swinging in 360 motion by small increments when triggered rather than swinging open at a certain angle before reverting back to it’s original position like any traditional door and it doesn’t even wind up at the same spot when it finally comes around.
Here’s my script on the local side:
local UIS = game:GetService("UserInputService")
local DoorOpener = game:GetService("ReplicatedStorage").DoorOpener
UIS.InputBegan:Connect(function(Input,Istyping)
if Istyping then
return
elseif Input.KeyCode == Enum.KeyCode.E then
DoorOpener:FireServer()
end
end)
local Insight = false
while wait() do
if Insight == false then
Insight = true
local ButtonClone = script.Parent:Clone()
ButtonClone.Parent = workspace.CurrentCamera
ButtonClone.Adornee = workspace.Door
ButtonClone.TextLabel.Visible = true
end
end
if Insight then --you don't need to have the "== true"
if workspace.CurrentCamera:FindFirstChild("Button") then
workspace.CurrentCamera.Button:remove()
end
end
And here’s the script on the server side:
local Tween = game:GetService("TweenService")
local Door = workspace.Door
local DoorHinge = Door.PrimaryPart
local DoorOpener = game:GetService("ReplicatedStorage").DoorOpener
local Info = TweenInfo.new()
DoorOpener.OnServerEvent:Connect(function()
local TweenCreate = Tween:Create(DoorHinge,Info,{CFrame = DoorHinge.CFrame * CFrame.Angles(0,math.rad(90),0))
wait(0.5)
TweenCreate:Play()
end)
How do I make it so that when the player presses the button, the door swings open normally and when the button is pressed again, it swings back to its original position?