I have tried a few solutions like making sure the child is ready to be touched, but is still calling the nil value
local function onTouch() game.Workspace.Map7:FindFirstChild("Ground") function tween (part1,part2) camera.CameraType = Enum.CameraType.Scriptable camera.CFrame = part1.CFrame local tween = TweenService:Create(camera,tweeninfo,{CFrame = part2.CFrame}) tween:Play() wait(cutscenetime) camera.CameraType = Enum.CameraType.Custom end end game.Workspace.Map7.Ground.Touched:Connect(onTouch) wait(2) tween(game.Workspace.Cutsceneparts.Part1,game.Workspace.Cutsceneparts.Part2)
the 'attempted to call a nil value' error is coming from the last line.
The function tween
only exists inside the other function. Also two things are called "tween".
Rename the variable "tween" to something else. Create the function outside of the onTouch
function. Call the function inside the onTouch
function. Make sure a player came into contact with the part. Get rid of the :FindFirstChild()
function.
function tween (part1,part2) camera.CameraType = Enum.CameraType.Scriptable camera.CFrame = part1.CFrame local tweenanim = TweenService:Create(camera,tweeninfo,{CFrame = part2.CFrame}) tweenanim:Play() wait(cutscenetime) camera.CameraType = Enum.CameraType.Custom end local function onTouch(hit) if hit.Parent:FindFirstChild("Humanoid") then wait(2) tween(game.Workspace.Cutsceneparts.Part1,game.Workspace.Cutsceneparts.Part2) end end game.Workspace.Map7.Ground.Touched:Connect(onTouch)
this is the new (whole) script
local TweenService = game:GetService("TweenService") local camera = game.Workspace.Camera local cutscenetime = 7 local tweeninfo = TweenInfo.new( cutscenetime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0 ) function tween (part1,part2) camera.CameraType = Enum.CameraType.Scriptable camera.CFrame = part1.CFrame local tweenanim = TweenService:Create(camera,tweeninfo,{CFrame = part2.CFrame}) tweenanim:Play() wait(cutscenetime) camera.CameraType = Enum.CameraType.Custom end local function onTouch(hit) if hit.Parent:FindFirstChild("Humanoid") then wait(2) tween(game.Workspace.Cutsceneparts.Part1,game.Workspace.Cutsceneparts.Part2) end end game.Workspace.Map7.Ground.Touched:Connect(onTouch) wait(2) tween(game.Workspace.Cutsceneparts.Part1,game.Workspace.Cutsceneparts.Part2)