Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Finding the player?? Error below

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)

3 comments

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???

0

How would I find the player within a function?

0

@LightModed, he did pass the 'char' argument from the parameter in his CharacterAdded event. On line 19

1 answer

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.

2 comments

0

Still doesn't work..

0

Update with the new error? Post the edited code

This discussion is preserved as it was. New answers, comments, and votes are closed.