Help scripting a cannon ball reload UI HELP NEEDED

So I have a script inside of a cannon and I run some code to make the cannon fire but I have a boolean “cannonloaded” that is true but then becomes false when the cannon is fired. So there’s an if statement that detects if cannonloaded == true if it isn’t then the output prints “cannon not loaded”. I want to make it so that when the cannon isn’t loaded a UI appears telling the players to reload. I know that most UI needs to be used within a local script but I don’t know how would I do this as I need to detect if the cannon isn’t loaded first which is in a regular script.
Thanks.

1 Like

You can do 2 things: 1. after cannonloaded is set to “false” fire a RemoteEvent to all clients with the “cannonloaded” value. If the cannonloaded value is false then show the UI. Also fire the RemoteEvent when cannonloaded is set to “true” but then the remote event will be fired with the new value: true. The clients will recieve that value and because it’s true, the UI can go away again. 2. Make a loop: For example RunService.RenderStepped or something I less recommend: while true do task.wait() end and then check the value. You should make an instance called a boolvalue to be able to check it (and then also set the value of the boolvalue to the corresponding “cannonloaded” variable.

if it fired to all clients doesn’t that mean it would appear for all players? I just want it to appear for the player who’s cannon needs reloading.

Then just keep track of the player that last shot the cannon with a variable inside a script and then do FireClient(ThePlayerThatLastShot, cannonloaded)

And how would I track the player inside of a server script if I can’t use LocalPlayer ?
I need to make the variable for the player in the else statement which is if the cannon isn’t loaded this is also where im firing the remote event.

What? Get the player that fires the cannon. If you’re using a click detector or proximity prompt then it should automatically give you the player. Also, store the player variable at the top of the script and not in the else statement.