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

How come the gui doesn't get placed into the players HumanoidRootPart?

Asked by
iRunzs 20
4 years ago

Okay, so I am placing a gui in a player in a server sided script

local EToOpen = script:WaitForChild("EToOpen")

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local HRP = character.HumanoidRootPart
        local ETO = EToOpen:Clone()
        ETO.Parent = HRP
    end)
end)

But for some reason nothing happens??

2 answers

Log in to vote
0
Answered by
Epuuc 74
4 years ago
local EToOpen = script:WaitForChild("EToOpen")

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local HRP = character.HumanoidRootPart
        local ETO = EToOpen:Clone()
        ETO.Parent = HRP
    end)
end)

In the script you said, you have a script:WaitForChild() before the game.Players.PlayerAdded event is initialized. It will probably miss your player if there is stuff before that. Easy fix:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local HRP = character.HumanoidRootPart
        local ETO = script:WaitForChild("EToOpen"):Clone()
        ETO.Parent = HRP
    end)
end)
Ad
Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

I know the answer u see the problem here is that when the player is added to a game so is there character and it happens at the same time so when u say game.Players.PlayerAdded that means that the players character was added along with it so sense its already been added doing a function such as character.added would give u an error sense there were no added characters after the player was added sense they're the same thing therefore they are added at the same time. all u have to do is put the following code in the StarterPlayer.StarterCharacterScripts file in the game

local gui = script:FindFirstChild("BillboardGui") 
local character = script.Parent
local charhrp = character:FindFirstChild("HumanoidRootPart")

local guiclone = gui:Clone()
guiclone.Parent = charhrp
guiclone.Adornee = charhrp

i tested out this script and it works just fine and if u didnt know any script that u add to the StarterPlayer.StarterCharacterScripts file will be inside of the characters that join the game

Answer this question