" attempt to index function with 'play' "

I’m trying to make a system just where if you press a button you have the default roblox camera and if you press it again it goes to a set camera position. But when I press the button it says " attempt to index function with ‘play’ " on line 40. I have not seen any helpful posts that I could find. Any help is appreciated.

Code:

local TweenService = game:GetService("TweenService")

local camera = game.Workspace.Camera

local cutsceneTime = 0.25

local tweenInfo = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

function tween (part1,part2, part3, part4, part6)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame
	camera.CFrame = part2.CFrame

	local tween = TweenService:Create(camera, tweenInfo,  {CFrame = part4.CFrame})
	script.Parent.MouseButton1Click:Connect(function()
		camera.CameraType = "Scriptable"
	end)

	wait(cutsceneTime)

end

tween(game.Workspace.Test1, game.Workspace.Test2, game.Workspace.Test3, game.Workspace.Test4)

local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer


script.Parent.MouseButton1Click:Connect(function()
	local IsDe = game.Players.LocalPlayer.Character:WaitForChild("IsDefault").Value
	if IsDe == true then
		
		tween:play()
		IsDe = false
	end
	if IsDe == false then
		cam.CameraType = "Custom"
		cam.CameraSubject = player.Character.Humanoid
	end
	IsDe = true
end)

It looks like you’re trying to run :Play() on a function, which doesn’t exactly work. Try calling the function instead, with tween()

Edit: My mistake, I must of misunderstood. Are you trying to play tween which is nested within the tween function? If so, that won’t work as it’s only assessable within the function itself. You might want to make a global variable to store that tween (wouldn’t recommend that), or rewrite the way the tween works itself.

The problem with this script is that you can’t actually index tween. It’s a function. You can either call it, or make an actual tween tween and use :Play() on it. Also, Play() needs to be uppercase by my understanding(). play() and Play() are two different things.

Have your function tween return the tween itself (your var inside the function is called the same as the function, which is a bad idea. Do:

```
function tweenFun (part1,part2, part3, part4, part6)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame
	camera.CFrame = part2.CFrame

	local tween = TweenService:Create(camera, tweenInfo,  {CFrame = part4.CFrame})
	script.Parent.MouseButton1Click:Connect(function()
		camera.CameraType = "Scriptable"
	end)

	--wait(cutsceneTime)
      return tween 
end
```

------------------

local tween  = ```
tweenFun(workspace.Test1, workspace.Test2, workspace.Test3, workspace.Test4)
```
--------------- 

Calling this later on will run the tween (it won’t do the wait though)

1 Like

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