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

How do I make a brick disappear when I press the key R?

Player = game.Players.LocalPlayer
gui = script.Parent
Mouse = Player:GetMouse()
Box = script.Parent
Open = false

game.GetService("UserInputService").InputBegan:Connect(function(key)
 if key.Keycode == Enum.Keycode.R then
  if (Open == false) then
   Box.Transparency = 0
   Open = true
  elseif (Open == true) then
   Box.Transparency = 1
   Open = false
   
end
 end
end)

This is the code I have made. Whenever I press R nothing happens. Not sure what I did wrong.

5 comments

0

Might want to put in into a code block for people to read easier.

0

Thanks for the suggestion

0

Oh and by "disappear" you mean destroy the part or just set it to transparent?

0

I mean to set the transparent

0

Uh, at first, you need to make LocalScript with this text and put it in "StarterGear"(or Pack). At second, you need to change "Box = script.Parent" so "Box = game.Workspace.(yourpartname)". And this will work.

1 answer

Lol a simple mistake on your part contributed to your code not working.

if key.Keycode == Enum.Keycode.R then

should be

if key.KeyCode == Enum.KeyCode.R then

You should have gotten errors a bit like 10:03:12.857 - Keycode is not a valid member of InputObject

To figure out the correct ways to do this look here https://developer.roblox.com/en-us/api-reference/class/InputObject

2 comments

0

Now its giving me the error: 11:18:01 -- Expected ':' not '.' calling member function GetService

0

lol you also had game.GetService("UserInputService").InputBegan:Connect(function(key) should be game:GetService("UserInputService").InputBegan:Connect(function(key)

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