How do I make it so that, for example, when I press a key, the transparency of a part changes to 1, and when I press again, it changes to 0? I use Keyboardinput for this, and I want to know how to 'change' something when I press a key, and 'change' it back when I press it again.
Here you can see what I'm trying to do..
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then Tool.examplepartthing.Transparency = 0.65 wait() end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
You could try something like this :
didpress = false function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then if didpress == false then didpress = true Tool.examplepartthing.Transparency = 1 wait() else didpress = false Tool.examplepartthing.Transparency = 0 end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Please note I made this script directly in the answer, not in Roblox Studio, so I don't know if it'll actually work or not. :P