Player becomes nil in the next function

The title basically says it all-
I have the player set in the first function but when the second function comes around it’s nil…

I used print arguments to show whether the player is nil through each function.
Oddly, the character seems to stay between each function but the player still becomes nil nonetheless.

local Players = game:GetService("Players")

local player
local character
local backpack

function onPlayerAdded(player)
	
	backpack = player:WaitForChild("Backpack")
	
	character = player.CharacterAdded:Wait()
	
	print(player, "onPlayerAdded")
	print(character, "onPlayerAdded")
	print(backpack.Parent, "onPlayerAdded")
	awawa()
end

function awawa(player)
	print(player,"awawa")
	print(character,"awawa")
	print(backpack.Parent,"awawa")
end


game.Players.PlayerAdded:Connect(onPlayerAdded)


If anyone can possibly help it’d be greatly appreciated

You are never passing player into awawa(), so its player param is nil
just change your call to; awawa(player) and update function awawa(player) to also accept any other vars you need e.g.: awawa(player, character, backpack)

1 Like

the “player” in the first function is local, so the global one wont change. Try making the function’s parameter say smth like “plr”

Ohh ok I see! Thank you for the help!

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