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)
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)