How can I approach this problem?

My game has a “Click to Play” button that is only showed the first time the player joins. It also has a hunger system that runs on a server script.

Now,

I want the hunger system to run AFTER the player clicked the “Play” button.
I tried using a RemoteEvent but that makes the hunger system ONLY run when the event is fired (button clicked). Keep in mind the button can only be clicked once and then it disappears because the “Click to Play” screen only shows on join.
So if a Player died and respawned the hunger system wouldnt work unless “Play” is clicked again (wich is not possible because the “Play” screen only shows once)

How can I make it so that the hunger system runs indifinitely after “Play” is clicked.

A hunger system should be on the client as different players have different hunger levels (of course i may be wrong, but I find it easier to have one local script to manage hunger system for every player). As for the button, do this (I’m assuming you will use a local script for the hunger system here. If they are no gui’s associated with the system then put it in StarterPlayerScripts else put it in StarterGui. Lets assume you put it in startergui):

  1. Initially disable the local script
    Everytime a player joins, any instance in the ‘Starter’ folders will be cloned and placed in the respective area of the player e.g. a screengui in startergui will be placed in the player’s playergui. So when you put your hunger script in one of these they will be cloned
  2. Enable it when the button is pressed. You could do it like this:
local playbutton = script.Parent
local player = game.Players.LocalPlayer
playbutton.Activated:Connect(function()
   player.PlayerGui.ScreenGui.HungerSystem.Enabled = true
end)

With this, the script gets enabled when you press it. As you mentioned that the button will never be seen again, the script will stay enabled.

1 Like

I run the hunger system on the server to prevent possible exploiting, for example, a cheater making the hunger update every 9999999999 seconds instead of 12

I’ve decided to find a better approach for this, I will proabably remove the “Play” screen. Thanks for the help though.