Getting the character gives nil

Module script:

Player.GiveItemByServer = function(PLR, Item, Amount)
	local BackpackEvent = game.ReplicatedStorage.ToolsM.Backpack
	BackpackEvent:FireClient(game.Players.ZINTICK, Item, Amount)
	print(PLR.Character) -- nil                   
	if (PLR.Character:FindFirstChild(Item) and 
                  ^Gives error  
        PLR.Backpack:FindFirstChild(Item)) == nil then
		local c = game.ServerStorage.Usables:FindFirstChild(Item):Clone()
		c.Parent = PLR.Backpack
	end
	
end

server script calling it

PlayerM.GiveItemByServer(game.Players:FindFirstChild("ZINTICK"), "Trowel", 5)

no clue why its doing this. i am getting the correct object but its not working. i dont know why

Is it running before ZINTICK has actually loaded into the server? There’s usually at least a few seconds between the server script running and the Player actually joining the server.

You could try using a :WaitForChild()?

Also is there a reason you’re not using the PLR argument in your :FireClient function, rather than indexing the Player directly by name?

BackpackEvent:FireClient(PLR, Item, Amount)
1 Like

Are you running this script as soon as the server starts, if so the issue is the script is running before the character exists. I did some debugging and the script worked fine for me when I added this line:

repeat wait() until PLR.Character

This isn’t exactly optimal so what I’d do instead is make sure the player has a character when you’re calling the module

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.