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

weird error in the output?

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

✓ Accepted answer

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)

1 comment

0

oh my gosh, i am the lord of the dumbos

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.

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