Help on adding debounce to this spinner script? (already set up the basic spinner)
Asked by
4 years ago Edited 4 years ago
So, I just made a spinner and some code so every time you touch the spinner it changes the text to 1 less life and lowers your health by 10, and to prevent regeneration, I just made it set it to the number but -10 instead of subtracting 10 from the health. Anyway, my script does not work because it does not lower the lives and also lowers your health too fast. I tried to fix the last problem by making it wait but it still doesn't work. However I did figure out I need to add a debounce but how do I do that? Im new at lua so please try to keep it simple, help on this would be appreciated. This is my script:
002 | local Brick = script.Parent |
003 | local LivesA = workspace.spinner.Lives.BillboardGui.TextLabel.Text |
004 | local SpinningSpeed = workspace.spinner.PlatformBase.HingeConstraint.AngularVelocity |
008 | local function PlayerTouched(Part) |
009 | local Parent = Part.Parent |
010 | if game.Players:GetPlayerFromCharacter(Parent) then |
011 | if LivesA = = "Lives: 10" then |
013 | Parent.Humanoid.Health = 90 |
017 | Brick.Touched:connect(PlayerTouched) |
021 | local function PlayerTouched(Part) |
022 | local Parent = Part.Parent |
023 | if game.Players:GetPlayerFromCharacter(Parent) then |
024 | if LivesA = = "Lives: 9" then |
026 | Parent.Humanoid.Health = 80 |
030 | Brick.Touched:connect(PlayerTouched) |
034 | local function PlayerTouched(Part) |
035 | local Parent = Part.Parent |
036 | if game.Players:GetPlayerFromCharacter(Parent) then |
037 | if LivesA = = "Lives: 8" then |
039 | Parent.Humanoid.Health = 70 |
043 | Brick.Touched:connect(PlayerTouched) |
047 | local function PlayerTouched(Part) |
048 | local Parent = Part.Parent |
049 | if game.Players:GetPlayerFromCharacter(Parent) then |
050 | if LivesA = = "Lives: 7" then |
052 | Parent.Humanoid.Health = 60 |
056 | Brick.Touched:connect(PlayerTouched) |
060 | local function PlayerTouched(Part) |
061 | local Parent = Part.Parent |
062 | if game.Players:GetPlayerFromCharacter(Parent) then |
063 | if LivesA = = "Lives: 6" then |
065 | Parent.Humanoid.Health = 50 |
069 | Brick.Touched:connect(PlayerTouched) |
073 | local function PlayerTouched(Part) |
074 | local Parent = Part.Parent |
075 | if game.Players:GetPlayerFromCharacter(Parent) then |
076 | if LivesA = = "Lives: 5" then |
078 | Parent.Humanoid.Health = 40 |
082 | Brick.Touched:connect(PlayerTouched) |
086 | local function PlayerTouched(Part) |
087 | local Parent = Part.Parent |
088 | if game.Players:GetPlayerFromCharacter(Parent) then |
089 | if LivesA = = "Lives: 4" then |
091 | Parent.Humanoid.Health = 30 |
095 | Brick.Touched:connect(PlayerTouched) |
099 | local function PlayerTouched(Part) |
100 | local Parent = Part.Parent |
101 | if game.Players:GetPlayerFromCharacter(Parent) then |
102 | if LivesA = = "Lives: 3" then |
104 | Parent.Humanoid.Health = 20 |
108 | Brick.Touched:connect(PlayerTouched) |
112 | local function PlayerTouched(Part) |
113 | local Parent = Part.Parent |
114 | if game.Players:GetPlayerFromCharacter(Parent) then |
115 | if LivesA = = "Lives: 2" then |
117 | Parent.Humanoid.Health = 10 |
121 | Brick.Touched:connect(PlayerTouched) |
125 | local function PlayerTouched(Part) |
126 | local Parent = Part.Parent |
127 | if game.Players:GetPlayerFromCharacter(Parent) then |
128 | if LivesA = = "Lives: 1" then |
130 | Parent.Humanoid.Health = 0 |
134 | Brick.Touched:connect(PlayerTouched) |
138 | if LivesA = = "Lives: 0" then |
139 | LivesA = "Game Over.." |
EDIT: ANSWERED READ ANSWERS