Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Player is a nil value?

Asked by 4 years ago

My script is like this:

script.Parent.Shoot.OnServerEvent:Connect(function(PlrName,MouseyPos)
    print(MouseyPos)
        local Char = script.Parent
    local PlrInThisWeapon = game:GetService("Players"):GetChildren(Char.Name)
---------etc.

Why it got player's name, but can't find player? Help me!

0
no TheluaBanana 946 — 4y
0
btw its not sending the name of the player it is sending the player itself as an object TheluaBanana 946 — 4y

1 answer

Log in to vote
-1
Answered by 4 years ago

you have to follow the script, GetChildren does not get one object, it gets all the children, and Players object does not have GetChildren function.

I just use the following script

local player
for _,p in pairs(game.Players:GetPlayers()) do
    if p.Name == playerName then 
        player = p 
        break 
    end
end
0
You CAN use GetChildren on Players service though. memguy 161 — 4y
Ad

Answer this question