Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Overhead is not a valid member of part?

-- script
local overheadGUI = game.ServerStorage.Overhead

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		
		hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		hum.NameDisplayDistance = 0
		hum.HealthDisplayDistance = 0
		
		local head = char:WaitForChild("Head")
		local clone = overheadGUI:Clone()
		clone.Parent = head
		
		clone.Player.Text = player.Name
		clone.Level.Text = "Level "..player.Database.Level.Value

		hum.MaxHealth = player.Database.HP.Value
		clone.Frame.TextLabel.Text = math.floor(hum.Health).."/"..math.floor(hum.MaxHealth)
		
		hum:GetPropertyChangedSignal("Health"):Connect(function()
			local redZone = hum.MaxHealth / 4
			
			if hum.Health <= redZone then
				clone.Frame.Bar.BackgroundColor3 = Color3.fromRGB(200, 0, 0)
			else
				clone.Frame.Bar.BackgroundColor3 = Color3.fromRGB(0, 209, 0)
			end
			
			clone.Frame.TextLabel.Text = math.floor(hum.Health).."/"..math.floor(hum.MaxHealth)
			clone.Frame.Bar.Size = UDim2.new((hum.Health/hum.MaxHealth), 0, 1, 0)
		end)
	end)	
end)

LocalScript:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

char:WaitForChild("Head").Overhead.Parent = game.ReplicatedStorage -- here's the error	

I've tried everything I know, and when I reset my character, the overhead GUI appears for me as well, when normally it shouldn't appear for me, but for everybody else.

1 comment

0

My only guess is that the LocalScript runs faster than the ServerScript, so it looks for the OverheadGUI faster than the ServerScript can put the GUI inside the Head, try using a loop?

2 answers

Change the error line to:

char:WaitForChild("Head").Overhead.Parent = game:GetService("ReplicatedStorage") -- it is because RS is a service so you need to do this

1 comment

0

that literally has nothing to do with the error.

Add a LocalScript to the Overhead GUI containing just

script.Parent.Parent = game:GetService("ReplicatedStorage")

or wait for the Overhead GUI to be added to the Head using WaitForChild.

By the way, you don't have to wait for the Character in a StarterCharacterScript.

This discussion is preserved as it was. New answers, comments, and votes are closed.