What do you want to achieve? Keep it simple and clear!
I am trying to make a curtain tween up and down by pressing a button.
What is the issue? Include screenshots / videos if possible!
The tween isn’t playing,
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried print debugging, so I know where the error is. But the thing is, I do not know what is causing the error.
Local Script:
local plr = game.Players.LocalPlayer
local curtain = workspace:WaitForChild("StageCurtain")
local detector = workspace:WaitForChild("StageButton"):WaitForChild("ClickDetector")
detector.MouseClick:Connect(function()
print("Clicked")
game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("Clicked"):FireServer(curtain)
print("Fired Remote Event")
end)
Server Script:
local remote = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("Clicked")
local stage_db = true
remote.OnServerEvent:Connect(function(plr, arg)
print("Receiving remote event")
if arg.Name == "StageCurtain" then
if stage_db == true then
stage_db = false
local ts = game:GetService("TweenService")
local old = {-28.125, 8.812, -21.75}
local new = {-28.125, 27.062, -21.75}
if game.Workspace:WaitForChild("StageCurtain").Position == old then
print("Curtain is in old position")
local goal = {
Position = new
}
local ti = TweenInfo.new(5,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local t = ts:Create(game.Workspace:WaitForChild("StageCurtain"), ti, goal)
t:Play()
print("Playing tween")
t.Completed:Connect(function()
stage_db = true
end)
elseif game.Workspace:WaitForChild("StageCurtain").Position == new then
print("Curtain is in new position")
local goal = {
Position = old
}
local ti = TweenInfo.new(5)
local t = ts:Create(game.Workspace:WaitForChild("StageCurtain"), ti, goal)
t:Play()
print("Playing tween")
t.Completed:Connect(function()
stage_db = true
end)
end
end
end
end)
My print debugging got as far as: print(“Receiving remove event”).
Looks like you are using debouncing with stage_db for the first part of the server script but for the second you are not using debounce so that why your tween is not working also try not to use t.completed connect function etc… try using t.completed:wait() it will wait till the tween finishes then you can set the debounce stage_db to true
Please refrain from saying “it didn’t work”. That’s not enough information and most importantly we can’t do anything else with this information as we have to guess what didn’t work.
However I can guess what happen is that nothing happened and only the print “receiving remote event” is changed from the following issue:
You are comparing a Position which is a Vector3 | Roblox Creator Documentation with a table {}. This will always be false and hence nothing will ever happen since Vector3 is not a table. Moreover you cannot just replace the old position with a vector 3 like so:
local old = Vector3.new(-28.125, 8.812, -21.75)
You will get floating point errors like in this post.
It’s better to just have a bool that tells whether the curtain is open or closed.
I suggest looking at this tweening door example in this proximity prompt pack for an example on how to tween a door as it looks functional and perhaps you can modify it further more, Additionally there is no need to use a remote event in this scenario as ClickDetector | Roblox Creator Documentation have this special property:
ClickDetector events fire on both the client and the server, even when FilteringEnabled is on
local remote = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("Clicked")
local stage_db = true
remote.OnServerEvent:Connect(function(plr, arg)
print("Receiving remote event")
if arg.Name == "StageCurtain" then
if stage_db == true then
stage_db = false
local ts = game:GetService("TweenService")
local old = {-28.125, 8.812, -21.75}
local new = {-28.125, 27.062, -21.75}
if game.Workspace:WaitForChild("StageCurtain").Position == Vector3.new(-28.125, 8.812, -21.75) then
print("Curtain is in old position")
local goal = {
Position = Vector3.new(-28.125, 27.062, -21.75)
}
local ti = TweenInfo.new(5,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local t = ts:Create(game.Workspace:WaitForChild("StageCurtain"), ti, goal)
t:Play()
print("Playing tween")
t.Completed:Connect(function()
stage_db = true
end)
elseif game.Workspace:WaitForChild("StageCurtain").Position == Vector3.new(-28.125, 27.062, -21.75) then
print("Curtain is in new position")
local goal = {
Position = Vector3.new(-28.125, 8.812, -21.75)
}
local ti = TweenInfo.new(5)
local t = ts:Create(game.Workspace:WaitForChild("StageCurtain"), ti, goal)
t:Play()
print("Playing tween")
t.Completed:Connect(function()
stage_db = true
end)
end
end
end
end)