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

player gives me nil value?

So i am making a game but cant get it to work with this script i wrote and dont know why it gives me an nil value.

player = game.Players.LocalPlayer

if not player.leaderstats.mageClass == true then
	function Touched()
	local humanoid = Touched.Parent:findFirstChild("Humanoid")
	if (humanoid ~=nil) then
		humanoid.Health = 0 
	end
	end
elseif player.leaderstats.mageClass == true then
	local humanoid = Touched.Parent:findFirstChild("Humanoid")
	if (humanoid ~=nil) then
		humanoid.Health = 100 
	end
	end
	script.Parent.Touched:connect(Touched)
11:18:22.691 - Workspace.Model.Part.Script:3: attempt to index global 'player' (a nil value)
11:18:22.691 - Stack Begin
11:18:22.691 - Script 'Workspace.Model.Part.Script', Line 3

4 comments

0

is this a localscript?

1

LocalPlayer only works with a Local Script.

0

oh okay.

0

If this is fixed pls add [closed] ect to the question title

1 answer

Try

Player = game:GetService("Players").LocalPlayer

Also, I have called on the LocalPlayer within a server script several times, it is possible.

2 comments

0

To be frank, this is wrong.

0

Erm... No it's not possible to get LocalPlayer in Server Scripts. It may be possible in Play Solo mode in Studio. Check out the Blog Article "Common Mistakes" for more information.

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