-
What do you want to achieve? Keep it simple and clear!
Eating a food item will give energy -
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. - 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.