Hello! I am making a game, And I want a proximity prompt activated Sliding Door.
We’ve tried to use almost every script off the forums, Off many videos and nothing has worked thus far. I’m not sure if its something wrong with the door or the scripting or maybe the welding, But nothing has been working.
Also I am still new to scripting, so maybe keep that in mind?
here are two of the scripts we’ve used so far (there are more, i just couldn’t find them!)
local TweenService = game:GetService("TweenService")
local Door = script.Parent
local DoorRoot = Door.PrimaryPart
local toggle = false
function openDoor()
if toggle == false then
toggle = true
local DoorSlideInfo = TweenInfo.new()
local DoorSlideOpenTween = TweenService:Create(DoorRoot, DoorSlideInfo, {
CFrame = DoorRoot.CFrame * CFrame.new(DoorRoot.Size.X + 4.5, 0, 0)
})
DoorSlideOpenTween:Play()
DoorSlideOpenTween.Completed:Wait()
print(DoorRoot.CFrame)
wait(4)
local DoorSlideInfo = TweenInfo.new()
local DoorSlideCloseTween = TweenService:Create(DoorRoot, DoorSlideInfo, {
CFrame = DoorRoot.CFrame * CFrame.new(DoorRoot.Size.X - 4.93, 0, 0) -- Exact number for no gap.
})
DoorSlideCloseTween:Play()
DoorSlideCloseTween.Completed:Wait()
print(DoorRoot.CFrame)
toggle = false
end
end
Door.ClickDetector.MouseClick:Connect(openDoor)
And
local TweenService = game:GetService("TweenService")
local hinge = script.Parent.Doorframe.Hinge
local prompt = script.Parent.Base.ProximityPrompt
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local tweenInfo = TweenInfo.new(1)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
prompt.Triggered:Connect(function()
if prompt.ActionText == "Close" then
tweenClose:Play()
prompt.ActionText = "Open"
else
tweenOpen:Play()
prompt.ActionText = "Close"
end
end)