Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my cutscene script calling a nil value?

Asked by 3 years ago

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.

0
this isnt from the very start of the script btw memeyo234 0 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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)

0
how do i make it to wait until a certain part is touched? memeyo234 0 — 3y
0
nvm my bad lol memeyo234 0 — 3y
0
wait it didnt work memeyo234 0 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question