I have a script that makes the player's arms and head look to where the mouse is pointing. It was working fine before, but after I added some stuff to make sure it doesn't happen while the player is opening a door, I got an error that says "doorOpening is not a valid member of player" or something like that, even though it clearly was and I was able to use it in other scripts. Why do I get this error?
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local bool = Instance.new("BoolValue",player)
bool.Name = "doorOpening"
RunService.Stepped:connect(function()
local character = player.Character
local mouse = player:GetMouse()
local dy = mouse.Y - mouse.ViewSizeY / 2
local dx = mouse.X - mouse.ViewSizeX / 2
if character and (mouse.x <= mouse.viewSizeX / 2) then
if (player.doorOpening == false) then
character.Head.Neck.Transform = character.Head.Neck.Transform * CFrame.Angles(math.atan2(dy, dx) + math.rad(180), 0, 0)
character.LeftUpperArm.LeftShoulder.Transform = character.LeftUpperArm.LeftShoulder.Transform * CFrame.Angles(math.atan2(dy, dx) + math.rad(180), 0, 0)
character.RightUpperArm.RightShoulder.Transform = character.RightUpperArm.RightShoulder.Transform * CFrame.Angles(math.atan2(dy, dx) + math.rad(180), 0, 0)
end
else
if (player.doorOpening == false) then
character.Head.Neck.Transform = character.Head.Neck.Transform * CFrame.Angles(-(math.atan2(dy, dx)), 0, 0)
character.LeftUpperArm.LeftShoulder.Transform = character.LeftUpperArm.LeftShoulder.Transform * CFrame.Angles(-(math.atan2(dy, dx)), 0, 0)
character.RightUpperArm.RightShoulder.Transform = character.RightUpperArm.RightShoulder.Transform * CFrame.Angles(-(math.atan2(dy, dx)), 0, 0)
end
end
end)

4 comments
Oh, I just saw the error. My guess is that because you're parenting the boolean once it gets created it doesn't get a name beforehand.
However I fixed it. Make sure to read this: https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296
Thanks!
np