Won't identify part

Hi I’m trying to make a door open/close whenever the player presses E. This will not work

print("beginning")
local TweenService = game:GetService("TweenService")
local door =  game.Workspace:WaitForChild("Door")
local hinge =  game.Workspace:WaitForChild("Hinge")
local prompt = door.ProximityPrompt

local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.fromEulerAngles(0, 90, 0)
print(goalOpen.CFrame)

local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
print(goalClose.CFrame)

local tweenInfo =  TweenInfo.new(2)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
print(tweenOpen)
print(tweenClose)

prompt.Triggered:Connect(function()
	print("Triggered")
	if prompt.ActionText == "Close" then
		tweenClose:Play()
		prompt.ActionText = "Open"
		print("Closed")
	else
		tweenOpen:Play()
		prompt.ActionText = "Close"
		print("opened")
	end
end)

This will not work and in fact it is nto registering whether the prompt is being triggered because my print statement will not work. This is a warning I got:
Infinite yield possible on ‘Workspace:WaitForChild(“Door”)’

Can someone help me please

2 Likes

to fix the yielding problem do this with wait things

THING:WaitForChild("ThingName",30) -- 30 is the time itll wait
2 Likes

Thank you that fixed that yielding problem. It still is not working with
local door = game.Workspace:WaitForChild("Door")
I’m pretty sure since prompt is not being triggered

1 Like

Can you post an image of the explorer (the list of parts and stuff on the left or right side of your screen) where the script, door, and hinge are all visible? There are several things that could cause this bug

1 Like

any other errors?? Where is this script parented? What type of script is it?

1 Like


It is a local script

Also I realize it works when I ungroup the DoorModel. Is there a way to still do this and still group the door together??

1 Like

Hi


It is a local script

1 Like

That’s because you are searching for the Door from Workspace, even though you should search for Door in the DoorModel. Replace the quotted code with this:

local doorModel = game.Workspace:WaitForChild("DoorModel")
local door = doorModel:WaitForChild("Door")
3 Likes

What J_Angry said is correct

Unrelated, but I’d recommend not running scripts in ReplicatedStorage, as it’s meant for storing things only. You should instead run local scripts in StarterPlayer.StarterPlayerScripts

2 Likes

Thank you!! It worked, if anyone wants to see the finished script

print("beginning")
local TweenService = game:GetService("TweenService")
local door
local hinge
local doorModel = game.Workspace:WaitForChild("DoorModel", 30)
if doorModel then
	print("found doormodel")
	door = doorModel:WaitForChild("Door",30)
	hinge = doorModel:WaitForChild("Hinge",30)
end
local prompt = door.ProximityPrompt

local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.fromEulerAngles(0, 90, 0)
print(goalOpen.CFrame)

local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
print(goalClose.CFrame)

local tweenInfo =  TweenInfo.new(2)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
print(tweenOpen)
print(tweenClose)

prompt.Triggered:Connect(function()
	print("Triggered")
	if prompt.ActionText == "Close" then
		tweenClose:Play()
		prompt.ActionText = "Open"
		print("Closed")
	else
		tweenOpen:Play()
		prompt.ActionText = "Close"
		print("opened")
	end
end)
1 Like

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