Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my cutscene script calling a nil value?

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.

1 comment

0

this isnt from the very start of the script btw

2 answers

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)

3 comments

0

how do i make it to wait until a certain part is touched?

0

nvm my bad lol

0

wait it didnt work

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.