How to send "data" to other local scripts

  1. What do you want to achieve? Keep it simple and clear!
    Eating a food item will give energy
  2. What is the issue? Include screenshots / videos if possible!
    The energy script and the food script are both local and I dont know how to send data back and forth to them.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

(Local script located in the food item)

local Tool = script.Parent
local Handle = Tool.Handle
local NomAni = game.Workspace.NOMNOMNOM
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Sound1 = Tool.Eating
local DB = false

Tool.Activated:Connect(function()
	if not DB then
	DB = true
	local Ani = char.Humanoid.Animator:LoadAnimation(NomAni)
	Sound1:Play()
	Ani:Play()
	print("1")
		wait(2)
	DB = false
		
	end	
end)

(Local script located in starter character scripts)

local MinStamina = 0
local MaxStamina = 100
local char = script.Parent
local plr = game.Players.LocalPlayer
local Stamina = MaxStamina
local Amount = plr.PlayerGui.StaminaBar.StaminaBackround.Amount

local Asleep = false
local Seat = game.Workspace.SleepDetector:WaitForChild("Seat")

local debounce = false 


Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if Seat.Occupant ~= nil then
		local Char = Seat.Occupant.Parent
		debounce = true

		Asleep = true

		wait(1)
		debounce = false
	end
end)

Seat.ChildRemoved:Connect(function(child)
	if debounce == false then

		debounce = true

		Asleep = false

		wait(1)
		debounce = false
	end
end)



while wait(1) do

	if Stamina > MinStamina and Asleep == false then	
		Stamina -= 25
		print(Stamina)
		plr.PlayerGui.StaminaBar.StaminaBackround.StaminaBar2:TweenSize(UDim2.new(Stamina / MaxStamina, 0,1,0))

		Amount.Text = Stamina.. "/" ..MaxStamina

	elseif Asleep == true and Stamina < MaxStamina then
		Stamina += 25
		print(Stamina)
		plr.PlayerGui.StaminaBar.StaminaBackround.StaminaBar2:TweenSize(UDim2.new(Stamina / MaxStamina, 0,1,0))

		Amount.Text = Stamina.. "/" ..MaxStamina
	end
end

How do I go about doing this? Remember, I want it so that when the player eats his energy goes up.

BindableEvents and BindableFunctions are maybe what you are looking for.

You Shouldn’t update the stamina from a client-sided script but you can use BindableEvents like how XSiggeManx said

how would I update the stamina not client sided? Wouldnt that just connect every players stamina bar together?

That’s not how server-sided scripts work. You can store stamina data for every player and still be server-sided. There is no local player in server-sided scripts, but this can be applied to every player. You just pass when the client wants to run and sync the stamina server to the client, not the other way around, and there is your player.