Character just wont exist when called on client

So to mark it up here I have been stressing on this bug recently trying to convert my code into a framework it is quite successful until I ran to this issue

19:08:26.221 - Infinite yield possible on 'Workspace:WaitForChild("FerbZides")'
19:08:26.223 - Stack Begin
19:08:26.226 - Script 'Players.FerbZides.PlayerScripts.SCRIPTS.UIS', Line 79 - function Start

Code:

local Character = workspace:WaitForChild(Player.Name)

Its just so inaccurate of why it just doesn’t exist


PS:
Code or Module is place in StarterPlayer>StarterPlayerScripts

Fr this bug has been annoying me for months now and I cant get a single-ton solution for it

You can obtain the character through the player itself

tried that in other places and it would work but in this place that I am using rn just doesn’t seem to work

local Character
if player.Character then
    Character = player.Character
else
    player.CharacterAdded:Wait()
    Character = player.Character
end
3 Likes

this is a weird way to get the character of a player

These are the most appropriate ways

  • if a LocalScript is in StarterPlayer.StarterPlayerScripts (as in your case) you should do this
local LocalPlayer = game:GetService("Players").LocalPlayer
LocalPlayer.CharacterAdded:Connect(function (character)
	-- some code
end)
  • if a LocalScript is in StarterGui or StarterPack you should do this
local LocalPlayer = game:GetService("Players").LocalPlayer
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

-- some code

in this case (LocalScript is in StarterPlayer.StarterPlayerScripts), this will fail when the player resets. Character will point to the character that was destroyed.

it is more convenient to place the modules in ReplicatedStorage

Ngl and no Rudeness tolerated here
but your method is just way Inefficient why?

1. Modules
Modules can be placed anywhere for any concerns look up frameworks in the forum

2. Code
Your code added event can be done just quickly by doing this,

local Character = player.Character or player.CharacterAdded:wait()

That’s all for my concerns rn

I don’t understand why you’re saying this. I’m just trying to be formal.

Exactly. I said more Convenient. Not Mandatory or Efficient

This will not work because when you reset your character, Character will refer to the character that was destroyed. If you do this Character == Player.Character after resetting the character, it will give you false.

It’s also rude to respond in a rude way.