Hello! I have a door script that I want to use for my owner door model, though I have been having a lot of trouble with it. I am a garbage scripter so any help would be appreciated!
The issue seems to be the owner detection system. Most of the several variations I have tried seem to allow me to claim the door, but the animation won’t execute.
All of the owner door scripts I tried have been edited by me to fit my needs. The current script is very messy as I put the script on pause to come back to it after a few days.
If I can get the owner door working properly, I’ll be able to work on the other mechanisms such as locking and such on my own
Here is the full script (owner door mechanics & animation):
local ProximityPrompt = script.Parent
ProximityPrompt.ActionText = "Claim here"
local Door = script.Parent.Parent
local Connection
local OwnerId = 1
local Locked = false
Connection = ProximityPrompt.Triggered:Connect(function(plr)
ProximityPrompt.ActionText = "Claimed by ".. plr.Name
OwnerId = plr.UserId
Connection:Disconnect()
end)
ProximityPrompt.Triggered:Connect(function(plr)
if Locked and OwnerId ~= plr.UserId then
return
end
local Hinge = script.Parent.PrimaryPart
local opened = false
local Promt = script.Parent:WaitForChild("ProximityPrompt")
local 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()
script.Parent.ProximityPrompt.ActionText = "Close"
end
else
opened = false
for i = 1, 21 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
wait()
script.Parent.ProximityPrompt.ActionText = "Open"
end
end
end
Promt.Triggered:Connect(function(Players)
OpenDoor()
end)
script.Parent.Door1.ProxomityPrompt.Triggered:Connect(OpenDoor)
end)
Here is the animation taken from my other door models (works and is clean):
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()
script.Parent.ProximityPrompt.ActionText = "Close"
end
else
opened = false
for i = 1, 21 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
wait()
script.Parent.ProximityPrompt.ActionText = "Open"
end
end
end
Promt.Triggered:Connect(function(Players)
OpenDoor()
end)
script.Parent.Door1.ProxomityPrompt.Triggered:Connect(OpenDoor)
instead of doing forloops and exhausting yourself, why not use TweenService, it can smoothly help with animations and you can customize it and etc.
you can animate CFrames, positions, orientations with TweenService, and you can also use it for animating gui aswell!
try look at:
heres a example how to use Tweenservice:
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local OpenDoor = TS:Create(Door, TI, {--[[your property you want to change to]]})
OpenDoor:Play()
Thank you! I will look into this further. It’s probably obvious I have much more to learn. If this helps me come up with a solution, I will mark it as solved.
Yes
I’ve spent a LOT of time attempting to get the door to work, though the animation doesn’t start. I believe the claiming system itself worked, but when it checks for the owner value, it may be failing there. If that’s not it, perhaps the value isn’t setting the child (me) as owner.
First I recommend using :Once() for the claiming instead of :Connect() so you dont have to disconnect it.
Though we can just add this code into the other .Triggered connection.
Then I recommend having the following for the if return statements.
if locked then return warn("Door is locked, unable to open") end
if OwnerId ~= plr.UserId then return warn("Not the owner, unable to open") end
Also honestly I am generally confused what else is happening in the script, basically EACH single tile you run the triggered event, you make another triggered event with another proximity prompt which opens the door?? So honestly I just deleted that.
If you want multiple prompts to be able to open the door first make this whole thing a function, make one prompt have the :Once trigger like previously explained and make the other prompts visible once called.
Then just connect all of them to the function which I am directly connecting to right there. If you want to make a lock/unlock prompt that is literally just setting Locked to not Locked (but make sure to check if the door is closed or not.
local ProximityPrompt = script.Parent
ProximityPrompt.ActionText = "Claim here"
local Door = script.Parent.Parent
local OwnerId = 1
local Locked = false
local opened = false
ProximityPrompt.Triggered:Connect(function(plr)
if OwnerId == 1 then
ProximityPrompt.ActionText = "Claimed by " .. plr.Name
OwnerId = plr.UserId
Locked = true
end
if Locked then
return warn("Door is locked, unable to open")
end
if OwnerId ~= plr.UserId then
return warn("Not the owner, unable to open")
end
local Hinge = Door.PrimaryPart
local function OpenDoor()
if not opened then
opened = true
for i = 1, 21 do
Door:SetPrimaryPartCFrame(Hinge.CFrame * CFrame.Angles(0, math.rad(5), 0))
wait(0.03)
end
ProximityPrompt.ActionText = "Close"
else
opened = false
for i = 1, 21 do
Door:SetPrimaryPartCFrame(Hinge.CFrame * CFrame.Angles(0, math.rad(-5), 0))
wait(0.03)
end
ProximityPrompt.ActionText = "Open"
end
end
OpenDoor()
end)
After looking at the locked setting for this new script, I was able to change it to “unlocked”, allowing me to enter. Thanks so much! I still for sure plan to look at the tutorial posted by @anos111 to further improve my very obviously bad skills!