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

How do I add debounce to this cutscene trigger?

Asked by
par1d 19
4 years ago

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)
0
did it work? if so, can you accept my answer EmbeddedHorror 299 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
There seems to be an error with "if debounce=false then" par1d 19 — 4y
0
oops EmbeddedHorror 299 — 4y
0
try it now, my autocorrect turned '==' into '=' EmbeddedHorror 299 — 4y
Ad

Answer this question