Friends only door is not working

Hi!

So basically i created this script, but it doesn’t work. And it doesn’t even send me any error, so I don’t know what the problem is.


script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
		local userId = game.Players:GetUserIdFromNameAsync(plr.Name)
		if plr == script.Parent.Owner.Value or game.Workspace.BarricadeRoom1.PermissionPart1.CheckPart.BrickColor == BrickColor.new("Lime green") or plr:IsFriendsWith(userId) then

print("They're friends")

end)

Thank you in advance for your replies!

There’s nothing in the script that says that the door should have CanCollide set to false. Also, I believe you are missing an end to your if statement (after it prints “They’re Friends”).

Hi

So i edited the script a bit, and now it looks like this, but it’s still not working. If I remove the GetUserIdFromNameAsync, the script is perfectly working tho.

open = false

cfra = script.Parent.CFrame
siz = script.Parent.Size

function tween(part,poartpp,spded)
	local tweenService = game:GetService("TweenService")


local tweeningInformation = TweenInfo.new(
	
spded, -- Length
Enum.EasingStyle.Quint, -- Easing style of the TweenInfo
Enum.EasingDirection.Out, -- Easing direction of the TweenInfo
0, -- Number of times the tween will repeat	
false, -- Should the tween repeat?
0.1 -- Delay between each tween	
)


local Tween = tweenService:Create(part,tweeningInformation,poartpp)
Tween:Play()
end




cframas = cfra * CFrame.new(-1.5,0,0)
cframas2 = cfra
siza =  siz
siza2 = siz - Vector3.new(3,0,0)

can = true



script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
		if can then
		can = false
		local userId = game.Players:GetUserIdFromNameAsync(plr.Name)
		if plr == script.Parent.Owner.Value or game.Workspace.BarricadeRoom1.PermissionPart1.CheckPart.BrickColor == BrickColor.new("Lime green") or plr:IsFriendsWith(userId) then
			

		
		script.Parent.Sound:Play()
		
	if open then
		open = false
tween(script.Parent,{CFrame = cframas2,Size = siza},1)

	else
		open = true
tween(script.Parent,{CFrame = cframas,Size = siza2},1)
wait(3)
open = false
tween(script.Parent,{CFrame = cframas2,Size = siza},1)
script.Parent.Sound:Play()
				end
			end
else
			
		
	
	
	
		
	end
	wait(3)
	can = true
end)


Also, thank you for your answer.

Are you setting the value of owner? I tried remaking your script and it works when I do that.

if plr == script.Parent.Owner.Value or game.Workspace.BarricadeRoom1.PermissionPart1.CheckPart.BrickColor == BrickColor.new("Lime green") then

Basically, the script works if I leave the script like this

if plr == script.Parent.Owner.Value or game.Workspace.BarricadeRoom1.PermissionPart1.CheckPart.BrickColor == BrickColor.new("Lime green") then

but it doesn’t with this

if plr == script.Parent.Owner.Value or game.Workspace.BarricadeRoom1.PermissionPart1.CheckPart.BrickColor == BrickColor.new("Lime green") or plr:IsFriendsWith(userId) then

That is because a player cannot be friends with themselves. The code you wrote assigns “userId” to the player opening the door’s UserId. Did you mean to put owner.Value:IsFriendsWith(userId)

Omg yes, I am so dumb. Thank you so much, it’s working!

1 Like