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

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

Asked by 6 years ago
Edited 6 years ago

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)

0
The error is on line 6 User#21908 42 — 6y
0
I was kicking the player before the script had time to load. User#21908 42 — 6y
0
Well that is why then. royee354 129 — 6y
0
thx for your efforts though User#21908 42 — 6y

1 answer

Log in to vote
0
Answered by
royee354 129
6 years ago
Edited 6 years ago

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

0
But player should not be nil. User#21908 42 — 6y
0
I want player to exist User#21908 42 — 6y
0
~= means not equal to royee354 129 — 6y
0
It will probably perform when the player is not nil with what I have mentioned. royee354 129 — 6y
View all comments (2 more)
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. User#21908 42 — 6y
0
You want a check to see if it could find the player. Dog2puppy 168 — 6y
Ad

Answer this question