I have it so when a player touches a part it triggers an animation, but it triggers multiple times. Ive solved this before I just dont remember how I did it, is there a wiki page or anything on this?
Heres the script, its under starterplayer. Because thats where all my scripts go that are vital for the player.
local trigger = game.Workspace.AnimationRunners.AnimationRunner1 local player = game.Players.LocalPlayer local cutscene1 = trigger.Cutscene1 repeat wait() until player.Character trigger.Touched:connect(function() local animation1 = player.Character.Humanoid:LoadAnimation(cutscene1) animation1:Play() end)
I only want it to trigger one time for forever... Dun dun daaaaah (unless they rejoin)
Try this.
local trigger = game.Workspace.AnimationRunners.AnimationRunner1 local player = game.Players.LocalPlayer local cutscene1 = trigger.Cutscene1 local PlayedAlready = nil repeat wait() until player.Character trigger.Touched:connect(function() if not PlayedAlready then local animation1 = player.Character.Humanoid:LoadAnimation(cutscene1) animation1:Play() PlayedAlready = true end end)
This is referred to as debounce or when you create a variable to prevent something from cycling through multiple times when unwanted. Whenever the player activates it the first time it changes the variable "PlayedAlready" to true, by doing so if touched again it will not run as PlayedAlready is no longer nil or false.
Just add a variable, for example, local used = false
. Then just make the touch check if it is false and then change it to true. However, once per game would mean creating a bool value within the player on join and doing the same as with the variable. If you need more clarifications, don't hesitate to ask.