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”)’
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
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
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")
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
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)