I can't get this tween to work

  1. 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.

  2. What is the issue? Include screenshots / videos if possible!
    The tween isn’t playing,

  3. 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”).

Any help is appreciated!

3 Likes

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

1 Like

I tried your solution and it didn’t work.

Add a print statement between these 2 lines.

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

2 Likes

I just tried this, it didn’t work.

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)

Also, I do not want to use proximityPrompts.

1 Like

Position requires a valid Vector3 value, not a table
image

A question, StageCurtain is a BasePart right? not a model or anything else

Hey @Arctic_CitadeI! Looks like this is not how it works.

Try looking at some Lua coding sites for the solution.

You cannot tween a part/model with a table, you need to use Vector3 as that’s the main position thing in Roblox. It should be like this:

local old = Vector3.new(-28.125, 8.812, -21.75)
local new = Vector3.new(-28.125, 27.062, -21.75)

I tried that and it didn’t work.

Yes, it is a BasePart, not a model.

I know most of Lua already, I’ve done many things like this before. For some reason it just doesn’t seem to work this time.

You need to convert these values:

into Vector3 values:

In addition, try making sure arg.Name really is StageCurtain and not something else.

I changed the Vector3 tables into values but it still doesn’t work. And yes, arg.Name is StageCurtain.

Again, you can’t compare a Vector3 with a table. .Position is a Vector3. Not a table. Replace them with vector3s.

EDIT: Nvm, just saw that this was answered.