Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't this script detect a boolean value?

Asked by
shackfu 14
4 years ago

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)

1 answer

Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
4 years ago
Edited 4 years ago
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local bool = Instance.new("BoolValue")
bool.Name = "doorOpening"
bool.Value = false
bool.Parent = player

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.Value == 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
    elseif (player.doorOpening.Value== 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)

I'm guessing the reason why it was not working was because of the fact that you forgot to put .Value.

0
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. Mr_Unlucky 1085 — 4y
0
Thanks! shackfu 14 — 4y
0
np Mr_Unlucky 1085 — 4y
Ad

Answer this question