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

Attempt to index nil?

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)

2 comments

0

It think it's because you just specified a model or part at "if game.Workspace["Scp 096"]", and not a value.

0

so i am doing lookvector wrong? can you show me how to do it?

1 answer

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

2 comments

0

how would i fix it on this script?

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.

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