GetPlayerFromCharacter() Not Working 2

Based on the previous post,I checked my code and I have no typing error.

And the GetPlayerFromCharacter() still doesn’t work
Here is the script (StarterCharacterScript) :


Local player = game:GetService("players"):GetPlayerFromCharacter (script.Parent)

player.Backpack.ChildAdded:Connect(function(tool)
...
end)

The script has error and the GetPlayerFromCharacter() returns nil.

What’s happening now? What should I do? Is it a bug?

P.s. The script cannot move to StarterPlayerScripts since some functions in the script undergo character.

I think you accidentally spelled “players” with a lowercase “P”. It should be uppercase.

1 Like

There is a space on the first line between the GetPlayerFromCharacter and the opening bracket.

1 Like

local with an lowercase ‘l’ and Players with a capital ‘P’

2 Likes

This is the typing mistake when I typed in devforum.
It’s P in my game’s script

This is the autofill error when I typed the post on mobile

image

1 Like

As I said to scorpionbloodking, it’s just a typing error in devforum

The script run fine.
The function in the script still can be runned.

Maybe it’s a display error?

Where is the script placed? The only place where this script would work would be the players Character, as script.Parent would have to equal the character. Can you not just do a playerAdded event and fetch it that way?

1 Like

Use WaitForChild()
e.g. local backpack = player.Backpack or player:WaitForChild(“Backpack”)

1 Like

It’s in StarterCharacterScript

I don’t think it’s about the backpack error now.
I think this should be a display error.
I just runned the game once and I found out that the function related to the backpack in the script

player.Backpack:Connect(function (tool)
end)

still can properly run despite of the error displayed in developer console.

You can still get the local player even if the Local Script si located on StarterCharacterScripts, just do

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

I don’t know if this is what you mean or why are you using this function in a LocalScript if I didn’t understand something, tell me.

1 Like

It’s not a local script, it’s a normal script in StarterCharacterScript

Maybe just use PlayerAdded on ServerScriptService?

1 Like

Update:
The script works fine after adding delay

If not game:IsLoaded() then
game.Loaded:Wait()
end
2 Likes

That’s Great! I was also was having a problem with GetPlayerFromCharacter() Because i was making a region that would detect other humanoids and when i use this function to get the player from the character. it would return nil or an error. The way i was able to fix this problem was wrap it in a pcall(function() Only Wrapped Wherever the player is being located and used. So just another idea if you get an error with this function

1 Like