local re = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local players = {}
game.Players.PlayerAdded:Connect(function(player)
local character = player.CharacterAdded:Wait()
players[1] = character
re:FireClient(player,players)
end)
— local script
local re = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
re.OnClientEvent:Connect(function(character)
while wait() do
print(character[1].HumanoidRootPart)
end
end)
Not exactly sure what’s exactly wrong, but noticed a few things:
I don’t think you need to use a table and for each player setting the table in place 1 to the character, you basically get a table with only one thing, which is the character, and fire it.
You can just fire the player with the character directly.
If you’re just firing the character, you don’t even need a variable outside of the connection, just fire it directly.
If you want to get the character from a local script, just put the local script in StarterCharacterScripts and use script.Parent, or use:
--local script outside of StarterCharacterScripts
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
You don’t need to fire an event to get the character from a local script
4. When the character gets added, the HumanoidRootPart does not get created immediately, therefore, you can use WaitForChild().
--Example
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local HMR = char:WaitForChild("HumanoidRootPart") --Will pause the script until the root part exists.
I am pretty sure you’re problem is whether that the local script wasn’t created yet, or that the HumanoidRootPart doesn’t exist yet.