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

attempt to index nil with "playerInf"?

The problem in my script is at line 9, the playerInf folder is in the LocalPlayer, and inside it is the intValue named teamPicked, and it cant change because of "attempt to index nil" my script to change the teamPicked value :

local cam = workspace:WaitForChild("Camera")
player = script.Parent.Parent.Parent.Parent
function onClicked()
 player.TeamColor = BrickColor.new("Bright red")
 player.Team = game.Teams.Red
 local character = game.Workspace:FindFirstChild(player.Name)
 character:findFirstChild("Humanoid").Health = 0
	cam.CameraType = "Scriptable"
	game.Players.LocalPlayer.playerInf.teamPicked.Value = 1
end
script.Parent.MouseButton1Down:connect(onClicked)

my script for the Instance.new that creates the folder and intValue:

local player = game.Players.LocalPlayer
local teamPickedInfo = Instance.new("Folder", player)
teamPickedInfo.Name = "playerInf"
local teamPickedValue = Instance.new("IntValue",teamPickedInfo)
teamPickedValue.Name = "teamPicked"
teamPickedValue.Value = 0

1 comment

0

player = script.Parent.Parent.Parent.Parent could be the problem. - not a loalscript?

2 answers

✓ Accepted answer

suggesting that this is not a local script

  • i'll use your player value

local cam = workspace:WaitForChild("Camera")
player = script.Parent.Parent.Parent.Parent
function onClicked()
 player.TeamColor = BrickColor.new("Bright red")
 player.Team = game.Teams.Red
 local character = game.Workspace:FindFirstChild(player.Name)
 character:findFirstChild("Humanoid").Health = 0
    cam.CameraType = "Scriptable"
    game.Players[player.Name].playerInf.teamPicked.Value = 1
end
script.Parent.MouseButton1Down:connect(onClicked)

2 comments

0

try this and see if it works.

0

wasnt using a localscript, it was a script, but it doesnt work, i get the error playerInf is not a valid member of player

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