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

Finding the player?? Error below

Asked by
NotPix 2
7 years ago
Edited 7 years ago

14:12:37.638 - ServerScriptService.Main_Script:92: attempt to index local 'player' (a nil value)

how would i make this work? The reason i ask is because i'm trying to organize the clothes within a folder thats in Assets. Then have it find the required clothes according to the team the player is on. CODE BELOW

local Storage = game:getService("ReplicatedStorage")

function Change_Clothes(char)
    for _,x in next,char:GetChildren()do
        if x:IsA("Hat")or x:IsA("Shirt")or x:IsA("Pants")then
            x:Destroy()
        end
    end

local   player = game.Players:GetPlayerFromCharacter(char.Parent)

    Storage.Assets[player.Team].Shirt:Clone().Parent = char
    Storage.Assets[player.Team].Pants:Clone().Parent = char
    Storage.Assets[player.Team].Hat:Clone().Parent = char
end

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
wait(1) Change_Clothes(char)
        print(player.Name.." has joined!")
end)
0
I may be wrong but you're getting the players character from "Char" which is a argument inside Change_Clothes, and it doesn't seem like you passed any values to the argument "char" at all??? LightModed 81 — 7y
0
How would I find the player within a function? NotPix 2 — 7y
0
@LightModed, he did pass the 'char' argument from the parameter in his CharacterAdded event. On line 19 Goulstem 8144 — 7y

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
7 years ago

The reason it's erroring is because you're calling the method on Workspace! If you go back to line 10, you put char.Parent, but you need to put char. GetPlayerFromCharacter requires the chawracter, which you already defined with char.

0
Still doesn't work.. NotPix 2 — 7y
0
Update with the new error? Post the edited code Shawnyg 4330 — 7y
Ad

Answer this question