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

Equip and Unequip items without inventory?

Asked by
clrik 8
6 years ago

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

0
Sir for now I want you to completely switch up and use UserInputService BlackOrange3343 2676 — 6y
0
How do I do that? clrik 8 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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

0
where do I put this? In a script or in the handle? clrik 8 — 6y
0
is it local, or regular, or a module? where do I put the script? clrik 8 — 6y
Ad

Answer this question