What would've been a question on fixing code is now just a question on PlayerScripts in general.

Last night while working on a script and debugging I noticed that this script

local player = game.Players.LocalPlayer
local char = player.Character
local Status = player.PlayerGui.BillboardGui
local top = Status.Frame.Top
local bottom = Status.Frame.Bottom

local function updateText()
	top.Text = tostring(player)..[[
	HumanoidState]]
	bottom.Text = tostring(char.Humanoid:GetState())
end

char.Humanoid.StateChanged:connect(updateText)

worked perfectly when a descendant of PlayerGui, but when put into StarterPlayerScripts, the Humanoid.StateChanged would stop registering after death.

Is there a reason why that happens, and is there a fix for this in the future, so my future doesn't have to involve PlayerGui being filled to the brim with assorted things.

I'm mostly interested in the mechanics behind why this happens. Thanks,

MBacon15

2 comments

1

Try putting it into StarterCharacterScripts, as scripts there will be cloned and parented into the player every time the player dies.

0

Give an answer so I can credit you properly, thanks