"GUI is not a valid member of StarterCharacterScipts"

My script is a d20 roll and it should pop the given number result above the player’s head but when running it the second time this error message pops up

local D20Event = game.ReplicatedStorage.D20Event
D20Event.OnServerEvent:Connect(function(plr)
for z = 0, 20 do
local a = math.random(1, 20)
game.StarterPlayer.StarterCharacterScripts.GUI.Parent = plr.Character.Head
plr.Character.Head.GUI.Number.Text = a
end
end)

Use :Clone() to clone the Gui as there is only 1 version. You’re moving the GUI out of StarterCharacterScripts and so when it loops again and tries to find the GUI it ends up nil because there’s nothing there. Also I think StarterCharacterScripts automatically parents its children into the character but that might just be for scripts

1 Like