Gui is not part of playergui

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want a script that removes 100 length from a bar called hunger.

  2. 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”
    Screenshot 2023-08-19 035731
  1. 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)
1 Like

Try using WaitChild() maybe it hasn’t loaded in properly

1 Like

As @Mxcentric said, try using WaitForChild(). Also use task.wait() instead of wait() :slight_smile:

1 Like

I find usually it doesn’t load in yet, as scripts load first ( after server I believe ). Also sorry for any grammar mistakes I’m writing this on a 6 year old iPad lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.