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.
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)