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

Equip and Unequip items without inventory?

Is there a way to equip and unequip items on keypress? It would work with transparency...probably...

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,false)

And then somehow there is a script when you're holding a tool and when you hit a key (I, Z, E, Q, O, etc.).

I tried this script...made by me...

--- Objects ----
local glass = script.Parent.Parent.Handle

--- Scripts ----
function keyDown(key)
	if key == "I" then
		glass.Transparency = 0
	end
end 

function keyDown(key)
	if key == "I" then
		glass.Transparency = 1
	end
end

It didn't work. Becuase I'm bad a scripting...Don't judge me.

So if you can help me, or show an example? Then I would really appreciate it. Thanks :3

2 comments

0

Sir for now I want you to completely switch up and use UserInputService

0

How do I do that?

1 answer

✓ Accepted answer

Well you would first off, use UserInputService. When using UIS, here's a few things you should take note of. Connecting a function to UIS's InputBegan event, there's a parameter that holds the input. Here's what you would do:

local UIS = game:GetService('UserInputService')

local glass = workspace.ExampleGlass -- put glass Reference here

local Pressed = false -- a debounce

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.I then
		if not Pressed then
			Pressed = true
			glass.Transparency = 1
		else
			Pressed = false
			glass.Transparency = 0
		end
	end
end)

The input object is kind of an Instance since it has properties One of those properties being KeyCode, an Enum

2 comments

0

where do I put this? In a script or in the handle?

0

is it local, or regular, or a module? where do I put the script?

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