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

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

Asked by 4 years ago
Edited 4 years ago
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.

0
Might want to put in into a code block for people to read easier. XviperIink 428 — 4y
0
Thanks for the suggestion EmorchThe_Robloxian 0 — 4y
0
Oh and by "disappear" you mean destroy the part or just set it to transparent? XviperIink 428 — 4y
0
I mean to set the transparent EmorchThe_Robloxian 0 — 4y
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. nazarthatjustwant -5 — 4y

1 answer

Log in to vote
0
Answered by
AizakkuZ 226 Moderation Voter
4 years ago
Edited 4 years ago

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

0
Now its giving me the error: 11:18:01 -- Expected ':' not '.' calling member function GetService EmorchThe_Robloxian 0 — 4y
0
lol you also had game.GetService("UserInputService").InputBegan:Connect(function(key) should be game:GetService("UserInputService").InputBegan:Connect(function(key) AizakkuZ 226 — 4y
Ad

Answer this question