Accessing values inside Player

I am trying to make a survived system by inserting a value inside of every player called Survived, and it is set to true when you are inside the round area. This is done by touching a part with a script inside of that part.

I get an error message from the script inside of the part that is touched saying “Attempt to index nil with survived ”, meaning that something is wrong in that it is not accessing the player’s value.

Here is the script inside of the part:

local plrValue = game.Workspace.PlrValue
local Players = game:GetService("Players")

function onTouched(hit)

	if hit.Parent:findFirstChild("Humanoid") then

		local Character = hit.Parent
		-- This is the correct way of getting the player from the character
		local Player = Players:GetPlayerFromCharacter(Character)
		local survived = Player:WaitForChild("survived")
		survived.Value = true
		plrValue.Value = hit.Parent.Name

	end
end

script.Parent.Touched:connect(onTouched)

Here is a screenshot of the Player and their value:

Thanks,
u_fep

I think you should insert some prints like print(Player) and print(Character) to be sure that player actually exists

you misstyped FindFirstChild here?

if hit.Parent:findFirstChild("Humanoid") then

Also add a :WaitForChild() instead

1 Like

Nevermind I’ve found solution, but thanks to everyone who helped.