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 3 years ago
Edited 3 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:

--Variables--
local Brick = script.Parent
local LivesA = workspace.spinner.Lives.BillboardGui.TextLabel.Text
local SpinningSpeed = workspace.spinner.PlatformBase.HingeConstraint.AngularVelocity
--End--

--Code--
local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 10" then
            LivesA = "Lives: 9"
            Parent.Humanoid.Health = 90
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 9" then
            LivesA = "Lives: 8"
            Parent.Humanoid.Health = 80
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 8" then
            LivesA = "Lives: 7"
            Parent.Humanoid.Health = 70
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 7" then
            LivesA = "Lives: 6"
            Parent.Humanoid.Health = 60
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 6" then
            LivesA = "Lives: 5"
            Parent.Humanoid.Health = 50
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 5" then
            LivesA = "Lives: 4"
            Parent.Humanoid.Health = 40
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 4" then
            LivesA = "Lives: 3"
            Parent.Humanoid.Health = 30
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 3" then
            LivesA = "Lives: 2"
            Parent.Humanoid.Health = 20
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait (1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 2" then
            LivesA = "Lives: 1"
            Parent.Humanoid.Health = 10
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 1" then
            LivesA = "Lives: 0"
            Parent.Humanoid.Health = 0
        end
    end
end
Brick.Touched:connect(PlayerTouched)

wait(1)

if LivesA == "Lives: 0" then
    LivesA = "Game Over.."
    SpinningSpeed = 0
end

EDIT: ANSWERED READ ANSWERS

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

2 answers

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

untested but try this:

--Variables--
local Brick = script.Parent
local LivesA = workspace.spinner.Lives.BillboardGui.TextLabel.Text
local SpinningSpeed = workspace.spinner.PlatformBase.HingeConstraint.AngularVelocity
--End--

--Code--
local function PlayerTouched(Part)
    local Parent = Part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        if LivesA == "Lives: 10" then
            LivesA = "Lives: 9"
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
        elseif LivesA == "Lives: 9" then
            LivesA = "Lives: 8"
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
        elseif LivesA == "Lives: 8" then
            LivesA = "Lives: 7"
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
        elseif LivesA == "Lives: 7" then
            LivesA = "Lives: 6"
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
        elseif LivesA == "Lives: 6" then
            LivesA = "Lives: 5"
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
        elseif LivesA == "Lives: 5" then
            LivesA = "Lives: 4"
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
        elseif LivesA == "Lives: 4" then
            LivesA = "Lives: 3"
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
        elseif LivesA == "Lives: 3" then
            LivesA = "Lives: 2"
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
        elseif LivesA == "Lives: 1" then
            LivesA = "Game Over.."
            Parent.Humanoid.Health = Parent.Humanoid.Health - 10
            wait(5)
            LivesA = "Lives: 10"
        end
    end
end
Brick.Touched:Connect(PlayerTouched(Brick))

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 — 3y
0
it works with me though mroaan 95 — 3y
0
OH my bad give me your discord so i can change my answer LOL mroaan 95 — 3y
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 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 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

--variables
local Debounce = false
local brick = script.Parent
--end

--script
brick.Touched:Connect(function(hit)
if not Debounce then
        if hit.Parent:findFirstChild("Humanoid") then
            if script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: X" then
                hit.Parent:findFirstChild("Humanoid").Health = 90
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: IX"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: IX" then
                hit.Parent:findFirstChild("Humanoid").Health = 80
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: VIII"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: VIII" then
                hit.Parent:findFirstChild("Humanoid").Health = 70
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: VII"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: VII" then
                hit.Parent:findFirstChild("Humanoid").Health = 60
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: VI"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: VI" then
                hit.Parent:findFirstChild("Humanoid").Health = 50
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: V"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: V" then
                hit.Parent:findFirstChild("Humanoid").Health = 40
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: IV"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: IV" then
                hit.Parent:findFirstChild("Humanoid").Health = 30
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: III"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: III" then
                hit.Parent:findFirstChild("Humanoid").Health = 20
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: II"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: II" then
                hit.Parent:findFirstChild("Humanoid").Health = 10
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: I"
            elseif script.Parent.Parent.Lives.BillboardGui.TextLabel.Text == "Lives: I" then
                hit.Parent:findFirstChild("Humanoid").Health = 0
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Game Over."
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Restarting..."
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Starting countdown until restart."
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "10"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "9"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "8"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "7"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "6"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "5"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "4"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "3"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "2"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "1"
                wait(1)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Begin!"
                wait(0.5)
                script.Parent.Parent.Lives.BillboardGui.TextLabel.Text = "Lives: X"
            end
        end
Debounce = true
wait(.5)
Debounce = false
end
end)
--end

Answer this question