Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to make a block remove only one live?

so this is the code i have for

local player
script.Parent.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
		player = game.Players:GetPlayerFromCharacter(hit.Parent)
		player.leaderstats.lives.Value = player.leaderstats.lives.Value - 1
	end
end)

but when i run the code and try it, it kills me but when i look at the leaderboard it can reduce my lives up to 4 times for one death i have tried a lot of things but im not sure what to do or how do i make it so the code is only run once

3 comments

0

here is the link if you want to play the game also im coming out with an update on my birthday 5/27/2020 (tomorrow)

0

i would love to hear feedback

1 answer

✓ Accepted answer
local player
debounce = false
script.Parent.Touched:connect(function(hit)
    if debounce == true then return end
    debounce = true
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.Health = 0
        player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.leaderstats.lives.Value = player.leaderstats.lives.Value - 1
        wait(5) 
	debounce = false
    end
end)

The debounce is first set to false before the brick is touched. If the debounce is set to true when the player touches it, the function will return, which just means it will stop and go back to the top. If it is false, it will go on and set the value to true. It will run through the code, killing the player, taking their lives away, and then it will wait five seconds. This is the default time it takes a character to respawn, and you can change it according to the time you have it set to. After the five seconds, you will be able to touch the brick again.

If this helped, please accept the answer :D

1 comment

0

i already found it right as you said it but if i didnt find it this would of helped me so still thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.