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

HumanoidRootPart is not a valid member of Camera?

Asked by 5 years ago

Hello!

I've been trying to create a script where it shows a player's name above their head (With a billboard gui) which works. Then, I'm trying add a part where if another player (Call him PL1) is at least 20 studs away from someone else (Call him PL2) then PL1 can not see PL2's gui and PL2 can not see PL1's gui. Output comes up saying, 'HumanoidRootPart is not a valid member of Camera,' help is greatly appreciated. Here is script:

local billboardgui = game:GetService("ServerStorage"):WaitForChild("BillboardGui")
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
    if player.Name == player.Name then 
        local clonedgui = billboardgui:Clone()
        clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
        clonedgui.TextLabel.Text = player.Name
        clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
        for i,v in pairs(workspace:GetChildren())do
                    local v1 = v.HumanoidRootPart.CFrame.p --It's either this
                    local v2 = char.HumanoidRootPart.CFrame.p --Or this
                    local max = 20
                    if (v1-v1).magnitude <=max then
                        clonedgui.Enabled = true
                    else
                        clonedgui.Enabled = false
                    end

                end
            end
        end)
end)



Again, help is greatly appreciated.

0
By the way please accept my answer if worked. Miniller 562 — 5y
0
What is the problem? Please tell me Miniller 562 — 5y

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
5 years ago
Edited 5 years ago

This loop

for i,v in pairs(workspace:GetChildren()) do
end

gets all children of workspace, and the first child/object is Camera, because that is the first object under Workspace (first in ABC). And this:

local v1 = v.HumanoidRootPart.CFrame.p

I will write Camera instead of v, because that's the object it loops. This tries to set v1 to Camera.HumanoidRootPart, which doesn't exist, and that's the problem. If you are trying to get players' HumanoidRootPart, you need to detect if the loop object is a Model, if the model's name is a player's name, and then you can get it's HumanoidRootPart. If you want, I will edit this and write there how can you do that. Oh and I noticed something:

    if player.Name == player.Name then
        ...
    end

This is just unnecessary, because player.Name is player.Name, so.. Like if you are writing if "Cheese" is "Cheese":D Hope this helps! EDIT: There is your code that should work (tested and it worked, no errors and the TextLabel just spawned in my head :'D):

local billboardgui = game:GetService("ServerStorage"):WaitForChild("BillboardGui")
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local clonedgui = billboardgui:Clone()
        clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
        clonedgui.TextLabel.Text = player.Name
        clonedgui.TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
        for i,v in pairs(workspace:GetChildren())do
            if game.Players:FindFirstChild(v.Name) then -- if there is a player called the model's/part's/ANYTHING'S name (you will need this):
                local v1 = v.HumanoidRootPart.CFrame.p
                local v2 = char.HumanoidRootPart.CFrame.p
                local max = 20
                if (v1-v1).magnitude <=max then
                    clonedgui.Enabled = true
                else
                    clonedgui.Enabled = false
                end
            end

        end
    end)
end)

0
um Miniller, the output is fixed, HOWEVER, I move 20 studs away, I still see it (Using LocalServer) and why is Line 13, if (v1-v1), shouldn't it be, if (v1-v2)? LennyPlayzYT 269 — 5y
0
? I just copied your script and added the thing you need to have to detect if V is a player's character.. You used v1-v1. Miniller 562 — 5y
0
Rly copying alvinbloxx? How can you know that? This day I didn't even visited youtube yet, why are you downvoting?? Miniller 562 — 5y
0
Also, I am just answered his question, if I would get the information from alvinbloxx I would write his name.. Miniller 562 — 5y
View all comments (7 more)
0
MINILLER i just said I copied it but tried to change stuff LennyPlayzYT 269 — 5y
0
Also I didn't even know about that video exist! I would never use that for a game because I just don't need it.. Miniller 562 — 5y
0
oh LennyPlayzYT 269 — 5y
0
Thanks for removing the down vote.. Miniller 562 — 5y
0
So Miniller do u know the problem? LennyPlayzYT 269 — 5y
0
What problem? I added everything to your script, you can use it now, and it will clone the TextLabel into every players' head. Miniller 562 — 5y
0
wow you use AlvinBlox? you're lame DeceptiveCaster 3761 — 5y
Ad

Answer this question