Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Overhead is not a valid member of part?

Asked by
bluzorro 417 Moderation Voter
4 years ago
Edited 4 years ago
-- 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.

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? killerbrenden 1537 — 4y

2 answers

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

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
0
that literally has nothing to do with the error. bluzorro 417 — 4y
Ad
Log in to vote
0
Answered by
Asceylos 562 Moderation Voter
4 years ago
Edited 4 years ago

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.

Answer this question