Tween Not Working

local Players = game:GetService("Players")
local TS = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

local CurrentCamera = workspace.CurrentCamera

local CamFolder = workspace.CameraHandler
local CameraPart = CamFolder.CameraPart
local OriginalPos = CamFolder.OriginalPos

local y = OriginalPos.Size.Y / 2
local z = OriginalPos.Size.Z / 2

task.wait(1)

CurrentCamera.CameraType = Enum.CameraType.Scriptable

function MovePart(part, y, z)
	local randomSpeed = math.random(1, 3)
	print("In MovePart Function") -- This prints
	local info = TweenInfo.new(randomSpeed, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	local props = {Position = part.Position + Vector3.new(0, y, z)}
	local tween = TS:Create(part, info, props)
	print("Went through Tween variables") -- This prints
	tween:Play()
	tween.Completed:Wait()
	print("Played Tween") -- This prints
end

function SetCam()
	print("Heartbeat") -- This prints
	CurrentCamera.CFrame = CameraPart.CFrame
end

RunService.Heartbeat:Connect(SetCam)

while true do
	task.wait()
	print("In Loop") -- This prints
	local randomY = Vector3.new(0, math.random(-y, y), 0)
	local randomX = Vector3.new(0, 0, math.random(-z, z))

	MovePart(CameraPart, randomY, randomX)
end

All the prints print, and there are no errors, but tween doesn’t play through.

(and the camera does go to the CameraPart.CFrame, it’s just that the tween doesn’t play)

I have no idea what is wrong, so any help is appreciated!

1 Like

Try changing the names of the MovePart functions parameters, The local y = OriginalPos.Size.Y / 2 might be causing the part to tween to its original position.

2 Likes
function MovePart(part, posY, posZ)
	local randomSpeed = math.random(1, 3)
	print("In MovePart Function") -- This prints
	local info = TweenInfo.new(randomSpeed, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	local props = {Position = part.Position + Vector3.new(0, posY, posZ)}
	local tween = TS:Create(part, info, props)
	print("Went through Tween variables") -- This prints
	tween:Play()
	tween.Completed:Wait()
	print("Played Tween") -- This prints
end

Thought this would work, since they were duplicates, but the tween still doesn’t play.
No errors either.

1 Like

the reason this doesn’t work is because you are basically putting (you can’t put vector3 inside of vecor3 like that)

{Position = part.Position + Vector3.new(0, Vector3.new(0, math.random(-y, y), 0), Vector3.new(0, 0, math.random(-z, z)))}

You need to change the randomY and randomX so they are only number and nothing else, either that or change the props so it says:

local props = {Position = part.Position + y + x}
2 Likes

Oh yeah! That was the issue, it works perfectly now, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.