I am trying to make a barrier that opens when you click a button, and closes when you click a separate button. I have tried to search for tutorials, but the most I can find is a part that tweens constantly.
The documentation on tweening is confusing me, and I don’t really understand if I need to add remote events or something.
If someone could link a tutorial that would be great. Thank you!
In the model, I have the two buttons and the part. Inside the buttons I have clickDetectors, and I have a localscript inside the part I am trying to tween. This is the script (which doesn’t work):
local TweenService = game:GetService("TweenService")
local Barrier = script.Parent
local openButton = script.Parent.Parent.Buttons.openButton
local closeButton = script.Parent.Parent.Buttons.closeButton
local info = TweenInfo.new(
2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
false
)
local tweenOpen = TweenService:Create(Barrier, info, {Position = -23.438, 9.25, 40.614})
local tweenClose = TweenService:Create(Barrier, info, {Position = -17.563, 3.375, 40.614})
openButton.ClickDetector.MouseClick:Connect(function(playerWhoClicked: Player)
tweenOpen:Play()
end)
closeButton.ClickDetector.MouseClick:Connect(function(playerWhoClicked: Player)
tweenClose:Play()
end)
I did that and deleted my localScript, but it doesn’t work. I would look at output in studio test, but for some reason studio test is acting up and isn’t working. Should I replace ‘function(playerwhoclicked)’ with just ‘(function(player)’?
If you found a way to fix the output, add a print statement after the event to see if it even went through. If not, try checking if something is blocking your click detector, maybe the part is too small, or the clickrange is too short. Those are the only ideas that come to mind at the moment.
It looks like it doesn’t go through. The only output relating to the script is:
21:50:14.740 Unable to cast to Dictionary - Server - Script:17
21:50:14.740 Stack Begin - Studio
21:50:14.740 Script ‘Workspace.barrierIn_left.Part.Script’, Line 17 - Studio - Script:17
21:50:14.740 Stack End - Studio
Line 17 in question is:
local tweenOpen = TweenService:Create(Barrier, info, {Position = -23.438, 9.25, 40.614})