Animated Owner Door Using Proximity-Prompt

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 :slight_smile:

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)

Help would be much appreciated!

1 Like

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()
2 Likes

i dont get it, are you trying to make the door owner claimable nd stuff? (mb im too tired to read properly)

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 :sob:
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.

where’s the script located? inside a prompt? because i see you doing

local ProximityPrompt = script.Parent

and you try to define the hinge like:

local Hinge = script.Parent.PrimaryPart

and you have other problem like… script.parent.proximityprompt?

script.Parent.ProximityPrompt.ActionText = "Open"

and other.

try do printing and debugging, it would help you out alot.

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)
2 Likes

also he wants it for the players who doesn’t claim the door can open it, if its not locked.

Then why did he write the code like that.

  1. Connect the lock proximity
    If opened then return end
    Set the locked value each time the the other value
  2. Connect the open proximity
    If locked then return end
    Open and do all the magic

?

i mean, i think he can able to change it himself ig.

Yeah, after failing a few times, I ended up trying to debug myself (terrible idea), then took a break, then tried to debug again :skull:

I’ll try this script. Thanks for the help!

1 Like

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!

1 Like

Now I will create a unlock function, I’m not exactly sure how I plan to go about it, so wish me luck! I really appreciate how kind you guys have been!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.