Adding gui to character on respawned not working?

I feel so stupid right now because somehow I cant figure out how to add a gui once in the character whenever they first load in and anytime they respawn, anything I’ve tried doesn’t work or has some other weird result

local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer

local powerBarGui = script.Parent

local function addGui(character: Model)
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart", true)
	
	if humanoidRootPart then
		local newPowerBarGui = powerBarGui:Clone()
		newPowerBarGui.Enabled = true
		newPowerBarGui.Parent = humanoidRootPart
	end
end

if localPlayer.Character then
	addGui(localPlayer.Character)
end

localPlayer.CharacterAdded:Connect(addGui)

I am unsure why you need a script to clone a Gui into the player, as Roblox already does this for you if you put the Gui into StarterGui. If you need the Gui to reset itself every time the player respawns, leave the ResetOnSpawn value enabled.

1 Like

its a billboard gui that needs to be cloned inside the player’s character

Nvm just used startercharacterscripts for htis I forgot

Oh, you should have clarified that bit, I would have given a solution earlier if that was in the original post. But yes, its simple to do that, just clone the BillboardGui into the player’s character. You should be able to do that inside of a CharacterAdded connection in a server script pretty easily.

1 Like

Ok thanks, my bad for not clarifying blud

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.