I have a game where, every round, a set of 5 obstacles is chosen, with each obstacle being harder than the last. You have 3 lives each round, but I’ve recently been having trouble with making the lives not go down multiple times on impact. It’s a bit more complicated than it might seem though.
I’ll define kill parts as these neon red objects that kill the player upon impact, and I’m defining water as an invisible layer under all the obstacles that also kills upon impact.
What works:
- When the player touches the water, the lives only go down once. This is intentional.
- The same thing happens with kill parts, it only goes down once. Again, intentional.
What doesn’t work:
- When the player simultaneously touches water and a kill part (e.g. if they rub against a kill part while falling into the water), the player’s lives will go down by 2 increments. For instance, if the player’s life count is 3, it’ll go down to 1.
- The server script in the respective heading.
Reproducing:
- To reproduce, join the game and find an obstacle with kill parts (red & neon colored). Go to that side and rub against it while falling into the water. Your lives will likely decrease by 2.
Attempted (and failed) debounce script:
This is a script in ServerScriptService that attempts to rectify the issue with multiple lives. However, it doesn’t work at all. It doesn’t cause alternate problems, but it doesn’t solve the one at hand either. It does not produce any errors.
game.Players.PlayerAdded:Connect(function(player)
local livesLeft = player:FindFirstChild("LivesLeft") -- IntValue stores in player for lives left
local debounce = false
livesLeft.Changed:Connect(function() -- when lives change
if debounce == true then
livesLeft.Value += 1 -- should reverse impact of double-decreasing by increasing only one unit, but this does not work
debounce = false
else
debounce = true -- if the debounce is not already on, turn it on
local triggers = { -- these are parts that should negate the debounce as these are your "start points"
workspace.StartPart1,
workspace.StartPart2,
workspace.StartPart3,
workspace.StartPart4,
workspace.StartPart5,
workspace.SpawnPart, -- in the lobby, in case your lives run out
}
for _, part in ipairs(triggers) do
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
if game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) == player then
debounce = false -- if any of them are touched, and the player that touched them is the player of interest, then turn off the debounce so it resets it
end
end
end)
end
end
end)
end)
Any help would be appreciated.