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 add debounce to this cutscene trigger?

Hey there, I have a script where once a player has stepped on a part a cutscene is played however I'd like there to be a debounce so the cutscene doesn't continuously play. How would I do this?

The script is below:

-- localscript in starterGui
local player = game.Players.LocalPlayer
local TweenService = game:GetService("TweenService")
local cam = workspace.CurrentCamera

local TouchPart = game.Workspace.ALt -- Change this to the part you want to be touched

function play(char)

    local PP = char.PrimaryPart
    cam.CameraType = Enum.CameraType.Scriptable

    local BCFrame = PP.CFrame * CFrame.new(0,0,0)
    local targetCFrame = PP.CFrame * CFrame.new(0, 0, 10)

    cam.CFrame = BCFrame 

    local tween = TweenService:Create(
        cam,
        TweenInfo.new(2),
        {CFrame = targetCFrame}
    )

    tween:Play()
    tween.Completed:Wait()
    cam.CameraType = Enum.CameraType.Custom
end

TouchPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- checking if the object that touched it is a player
        play(hit.Parent) -- plays the animation
    end
end)

-- This event below will run when the player is added. Delete it all if you do not want this!
player.CharacterAdded:Connect(function(character)
    wait(3)
    play(game.Players.LocalPlayer.Character)
end)

1 comment

0

did it work? if so, can you accept my answer

1 answer

you would add a db , in this case a variable

-- localscript in starterGui
local debounce=false--creating the variable
local player = game.Players.LocalPlayer
local TweenService = game:GetService("TweenService")
local cam = workspace.CurrentCamera

local TouchPart = game.Workspace.ALt -- Change this to the part you want to be touched

function play(char)
if debounce==false then
debounce=true--changing to true
    local PP = char.PrimaryPart
    cam.CameraType = Enum.CameraType.Scriptable

    local BCFrame = PP.CFrame * CFrame.new(0,0,0)
    local targetCFrame = PP.CFrame * CFrame.new(0, 0, 10)

    cam.CFrame = BCFrame 

    local tween = TweenService:Create(
        cam,
        TweenInfo.new(2),
        {CFrame = targetCFrame}
    )

    tween:Play()
    tween.Completed:Wait()
    cam.CameraType = Enum.CameraType.Custom
debounce=false--resetting to false


end
end

TouchPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- checking if the object that touched it is a player
        play(hit.Parent) -- plays the animation
    end
end)

-- This event below will run when the player is added. Delete it all if you do not want this!
player.CharacterAdded:Connect(function(character)
    wait(3)
    play(game.Players.LocalPlayer.Character)
end)

3 comments

0

There seems to be an error with "if debounce=false then"

0

oops

0

try it now, my autocorrect turned '==' into '='

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