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.