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

Attempt to index nil?

Asked by
3wdo 198
3 years ago

so i am trying to make a game with SCP 096 where if you look at it he will rage and kill you. im trying to use lookvector for the players head to do this but i never used lookvector so im also probably doing this wrong

game.Players.PlayerAdded:Connect(function(player)
    if game.Workspace["Scp 096"] == game.Workspace:FindFirstChild(player.Name).Head.CFrame.lookVector then
        print("test")
    end
end)
0
It think it's because you just specified a model or part at "if game.Workspace["Scp 096"]", and not a value. NoelGamer06 62 — 3y
0
so i am doing lookvector wrong? can you show me how to do it? 3wdo 198 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

When I get the "attempt to index nil" error, it's always meant I created a variable and never assigned it a type of value (or value itself).

I usually accidentally do this when I make variables inside of a function or conditional statement that is only being used in that statement, but never giving the variable a value or type.

Hope this helps, wolf

0
how would i fix it on this script? 3wdo 198 — 3y
0
@TheGamerCuber_YT check your script for variables that are made in functions or statements without setting a value or a type, and also check that any variables set to instances (like game.Workspace) are correct. wolffdonnaven 12 — 3y
Ad

Answer this question