Press 'E' to pick up assistance

I am trying to make a system where whenever the player presses a key on their keyboard, it would equip it into a toolbar.(already have the toolbar made)

Something like this:
image

I have spent countless hours struggling on how to actually create the system, ideas such as checking if the mouse is hovered over the BillboardGui, UserInput on the part. If someone could bother to assist, that would be greatly appreciated. I want someone to help guide me to it.

I appreciate all and any help I receive.

3 Likes

Not sure if it’s possible to check if the mouse is hovered over the BillboardGui but you could probably use something hacky with WorldToScreenPoint.

On the client you would have a loop checking if the player is within the part and if they are and they press E within a certain range, you would fire to the server to verify. You could make it so that if they are within X studs from the part, then a GUI shows up next to it saying “Press E to pick up”.

There are many ways to do this though, but this is how I would do it (note I typed this up on here without test, may not work as expected)

Local Script:

local player = game:GetService('Players').LocalPlayer
local uis = game:GetService('UserInputService')

local part = workspace.Part

local textLabel = script.Parent.TextLabel -- says "Press E to pick up"

local remoteEvent = game:GetService('ReplicatedService').RemoteEvent 
local inBounds = false

local dist = 25

uis.InputBegan:Connect(function(input, gameProcessed)
       if input.KeyCode == Enum.KeyCode.E and inBounds == true then
           remoteEvent:FireServer(part)
       else
           error('Not within bounds')
       end
end)

while true do
    local magnitude = (workspace.Part.Position - player.Character.HumanoidRootPart.Position).Magnitude
    if (magnitude < dist) then
        inBounds = true
    end
    wait()
end


Server:

local remoteEvent = game:GetService('ReplicatedStorage').RemoteEvent

local dist = 25 -- never trust the client so you could have a module w/ this data

remoteEvent.OnServerEvent:Connect(function(plr, obj)
       if (obj.Position - plr.Character.HumanoidRootPart.Position).Magnitude < dist then
             -- do your toolbar code
       end
end)


3 Likes

i actually like your idea

local remoteEvent = game:GetService('ReplicatedStorage').RemoteEvent

local dist = 25 -- never trust the client so you could have a module w/ this data

remoteEvent.OnServerEvent:Connect(function(plr, obj)
       if (obj.Position - plr.Character.HumanoidRootPart.Position).Magnitude < dist then
        local Clone = script.Parent:Clone() -- script.Parent because this script will be in the tool so no need for finding it
         Clone.Parent = player.Backpack
       end
end)

he can just clone the tool to his backpack

i almost forget that you need to add Debounce to your tool,so they wont rapidly pick it up,You should know how to use Debounce, Hoped i helped! :slight_smile:

Nice Suggestion @AdvancedDrone,Keep up the Good Work!

3 Likes

shirooo made a really good tutorial on this topic, you should watch it!

3 Likes

Why not have a part that is sized so the item is fully inside of it, and have a variable that gives the part a specific unique serial number (have a script that will give it a random number when the part is placed in the world). Have a local script in that would detect when a mouse is hovering over a part, and detect if mouse.hit has a serial number inside of it. If you press E it will fire the server with the select serial number with the part, and there will be a server script in the part that detects if the part has a serial number then placing the item of the parts parent into your inventory

1 Like