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