So I got a script here which makes sure your energy drains, but I only want it to start draining your Energy when you touched a part which fires a RemoteEvent, I got that but I don’t know how to make the script only start when the RemoteEvent has been activated.
I got this now:
local DECREASE_FREQUENCY = 24
local DECREASE_AMOUNT = 1
local INCREASE_AMOUNT = 90
game.ReplicatedStorage.EnergyStart.OnClientEvent:Connect (function() ------ will enable draining
then enable.Script
end)
game.Players.PlayerAdded:Connect(function(Player)
local Hunger = Instance.new("IntValue", Player)
Hunger.Name = "Hunger"
Hunger.Value = 100 -- hunger total
Player.CharacterAdded:Connect(function()
Hunger.Value = 100 -- this is so the hunger bar resets after spawn
end)
while wait (DECREASE_FREQUENCY) do
-- run the code in here/repeating.
if Hunger.Value <= 0 then
Player.Character:BreakJoints()
else
Hunger.Value -= DECREASE_AMOUNT
end
end
end)
game.ReplicatedStorage.Eat.OnServerEvent:Connect (function(Player)
Player.Hunger.Value += INCREASE_AMOUNT
end)