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

How do I make this code activate a cutscene by clicking on a part?

So I have made a button that has a ClickDetector and the script, but the problem is that it doesn't work from me simply clicking on the button.

Many tutorials on YouTube cover how to do activate cutscenes by touching the part but I don't want that, when I look at this code, I don't know what a single strip of code does because I have very basic coding skills and this is from a cutscene plugin from Ozzypig, once again no tutorials on YouTube on how to do this.

--name of cutscene
cutscene_id = "Cutscene1"

--"infinite"	= show whenever button is pressed
--"spawn"		= show once per spawn
--"enter"		= show once per gameplay
show_rule = "infinite"

--if show_rule is "infinite", how long after the end of showing the cutscene can they see it again?
debounce_time = 1

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

button = script.Parent
ls = button.CutsceneLocalScript

d = false

function showCutscene(player, sync)
	local n = ls:clone()
	n.Parent = player.Backpack
	if not sync then while n.Parent do wait() end end
end

function getTags(p)
	local cs = p:FindFirstChild("Cutscenes")
	if not cs then
		cs = Instance.new("IntValue", p)
		cs.Name = "Cutscenes"
	end
	return cs
end

function checkTag(p)
	return getTags(p):FindFirstChild(cutscene_id)
end

function setTag(p)
	local t = Instance.new("IntValue", getTags(p))
	t.Name = cutscene_id
end

function hasSeenCutsceneEnter(player) return checkTag(player) end
function hasSeenCutsceneSpawn(player) return checkTag(player.Character) end

function recSeenCutsceneEnter(player) setTag(player) end
function recSeenCutsceneSpawn(player) setTag(player.Character) end

function onTouch(part)
	--get player
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
	if not player then return end
	--check already watching
	if player.Backpack:FindFirstChild(ls.Name) then return end
	--check debounce
	if d then return end d = true

	if show_rule == "enter" then
		if not hasSeenCutsceneEnter(player) then
			showCutscene(player)
			recSeenCutsceneEnter(player)
		end
	elseif show_rule == "spawn" then
		if not hasSeenCutsceneSpawn(player) then
			showCutscene(player)
			recSeenCutsceneSpawn(player)
		end
	else
		showCutscene(player)
		wait(debounce_time)
	end

	d = false
end
	
button.Touched:connect(onTouch)

The context is that a player clicks on the button to solve a puzzle, therefore triggering this cutscene where the camera goes from Point A to Point B, I also added a sound id in the model but I don't where to put the code in to set it off.

2 answers

Hey there, first of all my suggestion for you is to get better at scripting instead of using premade stuff like plugins, models or scripts from the internet. Because if you dont understand the code and you want to change something you will have to ask people again. I would buy some books about coding and read them. For example the advanced coding book made by Heath Haskins. Also once you are able to script a little go to discord servers and go into a voice chat. Then talk to people ask questions and show people your code and get some feedback.

Now to your question.

  1. put a folder in workspace wich is called CutsceneParts

  2. put your part a and part b into that folder. IMPORTANT: call the first part a and the second one b | excactly how I wrote the names here | and make sure to Anchor them and set Transparency to 1

  3. Put a part in workspace and name it StartCutcenePart

  4. Add a ClickDetector to StartCutcenePart

  5. put a local script into StarterPlayer>StarterPlayerScripts

then paste the following code:

--Variables--

local CP = workspace.StartCutcenePart --workspace.StartCutcenePart is a reference to the part activating the cutscene. put your Parts name instead of StartCutcenePart--
local CD = CP.ClickDetector --The ClickDetector
local Cam = workspace.CurrentCamera --Camera
local CutsceneFolder = workspace.CutsceneParts -- The CutsceneFolder
local TimeBetweenEachCutscenePart = 4 -- The time the Tween("Animation") between point a and b takes
local playing = false --A variable to debounce
local TS = game:GetService("TweenService") -- Tweenservice
local TI = TweenInfo.new(TimeBetweenEachCutscenePart,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut) --Creating the Tweeninfo

--functions--
local function StartCutscene(start,destination) -- a function called StartCutscene
	Cam.CameraType = "Scriptable" --setting the cameramode to "Scriptable"
	if CutsceneFolder:FindFirstChild(destination) and CutsceneFolder:FindFirstChild(start) then --check if the block the animation should tween to and from is found
		if playing == false then --Checks if the cutscene has been activated already if not it will play the cutscene
			playing = true --Sets playing to true
			Cam.CFrame = CutsceneFolder:FindFirstChild(start).CFrame -- Setting the Cameras CFrame to part a (or your starting part)
			local Tween = TS:Create(Cam,TI,{CFrame = CutsceneFolder:FindFirstChild(destination).CFrame}) --Creating the Tween
			Tween:Play() --Playing the Tween
			Tween.Completed:Wait() -- Waits until the Tween has been finished
			Cam.CameraType = "Custom" --Sets the cameramode back to custom
			playing = false -- sets playing to false
		end
	end
end


--Main--
CD.MouseClick:Connect(function() 
	StartCutscene("a","b") --When the player clicks on the part the Function will run
end)

1 comment

0

100% true. You can't code if you don't know how.

Basically, first add a click detecter too the part.

If you want to start to make advanced stuff like this first you needa learn scripting and get the basics.

Also the folowing code you used wont work as needed and i suggust using something else You can use this

local part = -- the part
local detecter = part.ClickDetecter

detecter.MouseButton1Click:Connect(function()
	-- the script
end)

or you can just easily change the function of your script I don't think this script would work and i would make it differently.

If ya need some help you can dm me discord cancle5#0035

--name of cutscene
cutscene_id = "Cutscene1"

--"infinite"    = show whenever button is pressed
--"spawn"       = show once per spawn
--"enter"       = show once per gameplay
show_rule = "infinite"

--if show_rule is "infinite", how long after the end of showing the cutscene can they see it again?
debounce_time = 1

----------------------------------------
part = script.Parent
detecter = part.ClickDetecter
ls = button.CutsceneLocalScript

d = false

function showCutscene(player, sync)
    local n = ls:clone()
    n.Parent = player.Backpack
    if not sync then while n.Parent do wait() end end
end

function getTags(p)
    local cs = p:FindFirstChild("Cutscenes")
    if not cs then
        cs = Instance.new("IntValue", p)
        cs.Name = "Cutscenes"
    end
    return cs
end

function checkTag(p)
    return getTags(p):FindFirstChild(cutscene_id)
end

function setTag(p)
    local t = Instance.new("IntValue", getTags(p))
    t.Name = cutscene_id
end

function hasSeenCutsceneEnter(player) return checkTag(player) end
function hasSeenCutsceneSpawn(player) return checkTag(player.Character) end

function recSeenCutsceneEnter(player) setTag(player) end
function recSeenCutsceneSpawn(player) setTag(player.Character) end

function onTouch(part)
    --get player
    local player = game.Players:GetPlayerFromCharacter(part.Parent)
    if not player then return end
    --check already watching
    if player.Backpack:FindFirstChild(ls.Name) then return end
    --check debounce
    if d then return end d = true

    if show_rule == "enter" then
        if not hasSeenCutsceneEnter(player) then
            showCutscene(player)
            recSeenCutsceneEnter(player)
        end
    elseif show_rule == "spawn" then
        if not hasSeenCutsceneSpawn(player) then
            showCutscene(player)
            recSeenCutsceneSpawn(player)
        end
    else
        showCutscene(player)
        wait(debounce_time)
    end

    d = false
end

button.MouseButton1Click:Connect(onTouch)

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