What do you want to achieve?
I want to try and add a player animation when someone opens a door, can anyone help?
What solutions have you tried so far?
I tried adding a animation when the player opens the door but it doesn’t work and I don’t know what to do.
local Hinge = script.Parent.PrimaryPart
local opened = false
local Promt = script.Parent:WaitForChild("ProximityPrompt")
function OpenDoor()
if opened == false then
opened = true
for i = 1, 21 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
wait()
end
else
opened = false
for i = 1, 21 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
wait()
end
end
end
Promt.Triggered:Connect(function(Players)
OpenDoor()
end)
script.Parent.Door1.ProxomityPrompt.Triggered:Connect(OpenDoor)
You can use TweenService to create a door opening animation.
Fixed code:
--//Services
local TweenService = game:GetService("TweenService")
--//Variables
local Hinge = script.Parent.PrimaryPart
local Prompt = script.Parent:WaitForChild("ProximityPrompt")
--//Controls
local isOpened = false
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
--//Functions
local function OpenDoor()
if isOpened then
--//Close door
local doorTween = TweenService:Create(Hinge, tweenInfo, {
CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(-100), 0)
})
doorTween:Play()
doorTween.Completed:Wait()
else
--//Open door
local doorTween = TweenService:Create(Hinge, tweenInfo, {
CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(100), 0)
})
doorTween:Play()
doorTween.Completed:Wait()
end
isOpened = not isOpened
end
Prompt.Triggered:Connect(OpenDoor)
script.Parent.Door1.ProxomityPrompt.Triggered:Connect(OpenDoor)