You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want a script that removes 100 length from a bar called hunger.
-
What is the issue? In theory it should work but the game doesn’t acknowledge me trying to reference basic info.
- BasicInfo is not a valid member of PlayerGui “Players.irlkaleI.PlayerGui”
-
What solutions have you tried so far? I tried chat gpt and reworking the code.
(This script starts by a remote event and its in the ServerScriptService)
print(player.Name .. " has joined the game.")
wait()
-- Store the player reference in a local variable
local localPlayer = player
-- Now you can use the 'localPlayer' variable to interact with the joined player
print("Local player: " .. localPlayer.Name)
local GiveFoodEvent = game.ReplicatedStorage:WaitForChild("GiveFood") -- Correct name
local HungerBar = localPlayer.PlayerGui.BasicInfo.Image.Hunger
local sizeToSubtract = UDim2.new(0, 100, 0, 0) -- Adjust the pixel values as needed
GiveFoodEvent.OnServerEvent:Connect(function(player, coconut)
local currentSize = HungerBar.Size
wait(0.1) -- Introduce a small delay
HungerBar.Size = currentSize - sizeToSubtract
HungerBar:Update()
print("Done")
end)
end)