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

weird error in the output?

Asked by
theCJarmy7 1293 Moderation Voter
8 years ago
function onKeyPress(inputObject, gameProcessedEvent)
    if gameProcessedEvent then return end

    if inputObject.KeyCode == Enum.KeyCode.Z then
if script.Parent == true then
    script.Parent = false
    else script.Parent = true
        end
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

the script above is supposed to turn the scripts parent(a frame), invisible. when i press z, i get this error:

Players.Player1.PlayerGui.create.inventory.fds:7: bad argument #3 to 'Parent' (Object expected, got boolean)

2 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

You have to access the Visible property!

function onKeyPress(inputObject, gameProcessedEvent)
    if gameProcessedEvent then return end

    if inputObject.KeyCode == Enum.KeyCode.Z then
    script.Parent.Visible = not script.Parent.Visible -- shorten it up for ya
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

0
oh my gosh, i am the lord of the dumbos theCJarmy7 1293 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Line 06/07: You try to set your script's parent to "false." You can only set other objects in the "Parent" property.

EDIT: I hit answer before answering how to fix your script, instead of changing the script's "Parent" to false (which will never work,) change it's "Visible" property.

Answer this question