Im writing a script to open a door for my model but for some reason it doesnt work, the proximityprompt does what its supposed to. But the door model itself doesnt budge.
Heres the script
-- Variables
local TweenService = game:GetService("TweenService")
local door = script.Parent.DoorB
local hinge = script.Parent.Hinge
local prompt = door.ProximityPrompt
local doorOpen = {}
doorOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0) -- Triggers the door to rotate when opened
local doorClose = {}
doorClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0) -- Closed door
local tweenInfo = TweenInfo.new(1)
local tweenOpen = TweenService:Create(hinge, tweenInfo, doorOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, doorClose)
prompt.Triggered:Connect(function()
if prompt.ActionText == "Close" then
tweenClose:Play()
prompt.ActionText = "Open"
else
tweenOpen:Play()
prompt.ActionText = "Close"
end
end)
If anyone wants I can share details (like the properties) of the parts in my door model and show hiearchy. So yeah but also can someone PLEASE tell me whats happening becuase I sure don’t.
Is everything apart from the hinge unanchored? The hinge should be the only thing anchored. Every other connecting part should be unanchored with a WeldConstraint, with Part0 being the hinge and Part1 being the connecting part.
Providing more details like the properties would be useful.
Using the instances you referenced I tried recreating your door model and got it working like this.
DoorScript:
local TweenService = game:GetService("TweenService")
local door = script.Parent.DoorB
local hinge = script.Parent.Hinge
local prompt = door.ProximityPrompt
local doorOpen = {}
doorOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
local doorClose = {}
doorClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local tweenInfo = TweenInfo.new(1)
local tweenOpen = TweenService:Create(hinge, tweenInfo, doorOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, doorClose)
local open = false -- set this to true if its open by default otherwise keep it how it is
prompt.Triggered:Connect(function()
if open then
tweenClose:Play()
else
tweenOpen:Play()
end
prompt.ActionText = open and "Open" or "Close"
open = not open
end)
However just a slight problem. Everything is unanchored with the hinge being unanchored. However the door is apart of another model with a weld script in it to keep everything together. I shouldve specified this, but the door is part of a vehicle model.
Can you show the hiearchy of the vehicle?
You could create a WeldConstraint in the vehicle, set it’s Part0 to the RootPart of the vehicle and set the Part1 to the hinge of the door.
I’m not sure about if the Part0 should be the RootPart of the vehicle or even if the vehicle has a RootPart, that’s why I’m asking for the hiearchy of the vehicle.
Are there no parts apart from the doors in the car? I was trying to find the “main” part, the part that has the physics applied to it. And does the car have a RootPart?