so im trying to make the power handler for a five nights at freddy’s game and i need a equation that makes a wait() less, the more power users appear so like, when a door closes the power will decrease more i have a test script
local users = require(script.Users) -- the module that gets what light is on and what door is closed
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
while wait() do -- loop
if script.Power.Value > 0 then
local rate = #users:getUsers() -- returns the number of users
script.Power.Value = script.Power.Value - 1 -- decreasing
Player.PlayerGui.ScreenGui.Power.Text = "Power: "..script.Power.Value -- the power show
end
end
end)
end)
local Players = game:GetService("Players")
local users = require(script.Users)
local Time = 1--Time it will take
local Increment = 1.5--Put how much you want it to go down
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Time /= Increment
while script.Power.Value > 0 do --Since the while loop looks for anything true you can just put it in here
script.Power.Value -= 1
Player.PlayerGui.ScreenGui.Power.Text = "Power: "..script.Power.Value
wait(Time)
end
end)
end)
Players.PlayerRemoving:Connect(function(Player)
Time *= Increment --Makes it wait more
end)
I didn’t test it so please tell me if it doesn’t work.