Hi I’m trying to use proximity prompt so that when the player presses e on a drawer, the drawer will slide open (z axis -1 studs). This is my code. I’ve also welded accordingly
local cabinet = game.Workspace:WaitForChild("Cabinet")
local drawerModel = cabinet.Drawer
local hinge = drawerModel:WaitForChild("hinge")
local drawer = drawerModel:WaitForChild("drawer")
local prompt = drawer.ProximityPrompt
if prompt then
print("prompt was found")
end
local TweenService = game:GetService("TweenService")
if TweenService then
print(TweenService)
print("TweenService was found")
end
local goalOpen = {}
goalOpen = hinge.CFrame + Vector3.new(0, 0, -2)
local goalClose = {}
goalClose = hinge.CFrame + Vector3.new(0, 0, 2)
if goalOpen then
print(goalOpen)
print("goalopen was successfully made")
end
local tweenInfo = TweenInfo.new(2)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
prompt.Triggered:Connect(function()
print("propmt was triggered")
if prompt.ActionText=="Open" then
print("drawer opened")
tweenOpen:Play()
prompt.ActionText = "Close"
else
print("drawer closed")
tweenClose:Play()
prompt.ActionText = "Open"
end
end)
It won’t work though as it says “Unable to cast dictionary” to creating tweenOpen. I believe the issue is my creation of goalOpen and goalClose nad the usage of the CFrame.
I’m new to coding so I tried to do this without a tutorial and I am not sure if I’m on the right track.
Can someone help me please