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

[Solved]Why is plr a nil value(I should know this by now lol)?

Here is the script:

script.Parent.Touched:Connect(function(hit)
	if script.Parent.CanCollide then
		if hit.Parent:FindFirstChild("Humanoid") then
	
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			local plrName = plr.Name

Here is the error: 04:08:16.707 - Workspace.Tycoons.BlueTycoon.Essentials.TycoonStarterDoor.TycoonDoor.TycoonDoorScript:112: attempt to index local 'plr' (a nil value)

4 comments

0

The error is on line 6

0

I was kicking the player before the script had time to load.

0

Well that is why then.

0

thx for your efforts though

1 answer

If plr ~= nil then You might want to add to if cancollide then if can collide == true/false then

6 comments

0

But player should not be nil.

0

I want player to exist

0

~= means not equal to

0

It will probably perform when the player is not nil with what I have mentioned.

0

I know what it does I am not a noob. I want player to not be nil. As in how do I make player be the player who touched the object.

0

You want a check to see if it could find the player.

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