Whenever I test this script in Roblox Studio, it works fine. But when I open the client log in the developer console on the actual game, I get this error -
player.secretboy6.PlayerGui.LocalScript:3: attempt to index local 'char' (a nil value)
-and the script fails to work. How do I fix this?
local player = game.Players.LocalPlayer
local char = player.Character
local torso = char:WaitForChild("Torso")
Pos = Instance.new("Folder",script.Parent.Parent)
Pos.Name = "Position"
XPos = Instance.new("IntValue",Pos)
XPos.Name = "XPos"
YPos = Instance.new("IntValue",Pos)
YPos.Name = "YPos"
ZPos = Instance.new("IntValue",Pos)
ZPos.Name = "ZPos"
while 1==1 do
X = torso.Position.X
Y = torso.Position.Y
Z = torso.Position.Z
wait()
XPos.Value = X
YPos.Value = Y
ZPos.Value = Z
end
a = nil
function Jay()
local X = script.Parent.Parent.Position.XPos.Value
local Y = script.Parent.Parent.Position.YPos.Value
local Z = script.Parent.Parent.Position.ZPos.Value
if a == nil or a == true then
if X >= -5 and X <= 5 then
if Y >= 2 and Y<= 10 then
if Z >= 190 and Z <= 202 then
for i=1, 0.5, -0.1 do
script.Parent.Parent.PlayerGui.ScreenGui.PressFTo.TextTransparency = i
wait()
end
a = false
script.Parent.ScreenGui.chatFrame.FirstConversation.Disabled = false
end
end
end
end
if a == false then
if not(X >= -5 and X <= 5) or not(Z >= 190 and Z <= 202) then
for i=0.5, 1, 0.1 do
script.Parent.Parent.PlayerGui.ScreenGui.PressFTo.TextTransparency = i
wait()
end
a = true
script.Parent.ScreenGui.chatFrame.FirstConversation.Disabled = true
end
end
---------------------------
end
XPos.Changed:connect(Jay)
YPos.Changed:connect(Jay)
ZPos.Changed:connect(Jay)

2 comments
Players.secretboy6.PlayerGui.LocalScript:3: attempt to index local 'char' (a nil value)
Change char to player.Character or player.CharacterAdded:Wait(). Sometimes the character hasn't loaded yet in an actual client to server environment, so when the script tries to locate the character, it errors. CharacterAdded:Wait() will yield for that event if the player.Character is nil.