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

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:

001--Variables--
002local Brick = script.Parent
003local LivesA = workspace.spinner.Lives.BillboardGui.TextLabel.Text
004local SpinningSpeed = workspace.spinner.PlatformBase.HingeConstraint.AngularVelocity
005--End--
006 
007--Code--
008local function PlayerTouched(Part)
009    local Parent = Part.Parent
010    if game.Players:GetPlayerFromCharacter(Parent) then
011        if LivesA == "Lives: 10" then
012            LivesA = "Lives: 9"
013            Parent.Humanoid.Health = 90
014        end
015    end
View all 141 lines...

EDIT: ANSWERED READ ANSWERS

0
Use :Connect() instead of :connect() for newer work. RazzyPlayz 497 — 4y
0
give me your discord so i can try to help you mroaan 95 — 4y
0
give me yours CraftyAlphaMan 11 — 4y
0
mine's mrwan#2646 mroaan 95 — 4y
0
sent CraftyAlphaMan 11 — 4y

2 answers

Log in to vote
0
Answered by
mroaan 95
4 years ago

untested but try this:

01--Variables--
02local Brick = script.Parent
03local LivesA = workspace.spinner.Lives.BillboardGui.TextLabel.Text
04local SpinningSpeed = workspace.spinner.PlatformBase.HingeConstraint.AngularVelocity
05--End--
06 
07--Code--
08local function PlayerTouched(Part)
09    local Parent = Part.Parent
10    if game.Players:GetPlayerFromCharacter(Parent) then
11        if LivesA == "Lives: 10" then
12            LivesA = "Lives: 9"
13            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
14        elseif LivesA == "Lives: 9" then
15            LivesA = "Lives: 8"
View all 43 lines...

what it does if the player Lives was 1 and he touched the brick then he will die and after 5 seconds their lives will return to 10 if thats what you wanted i hope i helped!

0
no whenever i touch it it says attempt to call a nil value? CraftyAlphaMan 11 — 4y
0
it works with me though mroaan 95 — 4y
0
OH my bad give me your discord so i can change my answer LOL mroaan 95 — 4y
0
this is not the actual answer but he helped me a lot in making it, the real answer is below this one CraftyAlphaMan 11 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I am pretty sure the reason that it wasnt working was because I was changing it through a variable so. here it is, with debounce

01--variables
02local Debounce = false
03local brick = script.Parent
04--end
05 
06--script
07brick.Touched:Connect(function(hit)
08if not Debounce then
09        if hit.Parent:findFirstChild("Humanoid") then
10            if script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: X" then
11                hit.Parent:findFirstChild("Humanoid").Health = 90
12                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: IX"
13            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: IX" then
14                hit.Parent:findFirstChild("Humanoid").Health = 80
15                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: VIII"
View all 75 lines...

Answer this question