I’m making a simple door script. When a player interacts with the door, it will open or close depending on its current state. I’m using bindable events because I have an ai that needs to be able to open the door.
The issue that im currently having is that the bindable events seem to be messing with my tweenclose tween. When i dont use the bindable event, the tweens work just fine.
I have searched google if tweens didn’t work with bindable events, although I came up with nothing.
below ive listed the code that initiates the bindable event
local collectionservice = game:GetService("CollectionService")
local tweenservice = game:GetService("TweenService")
for i, door in pairs(collectionservice:GetTagged("Door")) do
local hinge = door.Hinge
local prompt = door.Door.ProximityPrompt
prompt.Triggered:Connect(function()
game.ServerStorage.Bindables.Door.Event:Fire(door)
end)
end
And here is the recieving end of the bindable event.
game.ServerStorage.Bindables.Door.Event.Event:Connect(function(door)
local TweenService = game:GetService("TweenService")
local hinge = door.Hinge
local prompt = door.Door.ProximityPrompt
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(door:GetAttribute("Angle"), math.rad(0), 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)
if prompt.ActionText == "Close" then
door:SetAttribute("Open", false)
door.Sounds.DoorClose:Play()
tweenClose:Play()
prompt.ActionText = "Open"
else
door:SetAttribute("Open", true)
door.Sounds.DoorOpen:Play()
tweenOpen:Play()
prompt.ActionText = "Close"
end
end)
I will also include the generic script that works, but doesnt support my main goal
local collectionservice = game:GetService("CollectionService")
local tweenservice = game:GetService("TweenService")
for i, door in pairs(collectionservice:GetTagged("Door")) do
local TweenService = game:GetService("TweenService")
local hinge = door.Hinge
local prompt = door.Door.ProximityPrompt
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(door:GetAttribute("Angle"), math.rad(0), 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
print("opened")
door:SetAttribute("Open", false)
print("opened 2")
door.Sounds.DoorClose:Play()
tweenClose:Play()
prompt.ActionText = "Open"
else
door:SetAttribute("Open", true)
door.Sounds.DoorOpen:Play()
tweenOpen:Play()
prompt.ActionText = "Close"
end
end)
end