How do I make a character appear when the user presses "Q" on their Keyboard

  1. I want to achieve something like this, where when a user presses a button on their keyboard, a “Defender” will pop up and fight for them. I just need the action part of when the user presses a button and will float at their side for a couple of seconds | Link: https://images-ext-1.discordapp.net/external/76bw_uQKEdiSHX_LcWVPRXeaj7zxR9VhzTUHdtg6VSU/https/i.gyazo.com/7b040fea4630d97e23df0b4e6b861f72.mp4

I have some of the script done, but I’m just stuck on where to go next:

`local StandID = 4464987098 --Find ID of Stand once made (Done)

local Equip = game.Workspace

function add()

--Function to get the Stand
local data = game:GetService("InsertService"):LoadItem(StandID)

local instance = data:GetChildren()
if #instance == 0 then
	data:Remove()
	return
end

–extra--------------------------------------------------------------
local summon = game.Players.LocalPlayer.Character:FindFirstChild(“Torso”)

game.workspace:GetService("InsertService"):Insert(data)

data:MoveTo(summon.Position + summon.CFrame.lookVector * 3)

data.Name = ("InsertedItem").. StandID

Equip.Handle.Drop:Play()

end


ableis = true
function PressKeyboardQ (PC)
if not ableis then
return
end

ableis = false

add()
wait(1)

Equip:Remove()

end

function PressKeyboardQ (PC)
if PC == nil then
print(“Pressing Q not avaible”)
return
end

PC.Image = "https://www.roblox.com/library/4464987098/Blackhole"
PC.Button1Down:connect(function() PressKeyboardQ(PC) end)

end
Equip.Equipped:connect(PressKeyboardQ)`

I’ve tried to look up some tutorials, but no dice.

I’ve tried to add and add on to this script, but nothing is working. I might be able to look at some more tutorials.

Are you able to help/give suggestions?

Sorry if the coding is a little messy, this is my second post.

What you will need to do is first collect the user’s input and then clone a template object into workspace via a remote event. If you want the object to follow the player you can either weld it or script it.

In order to get the input, you will need to use UserInputService to collect the key pressed event, see here:

UserInputService.InputBegan:Connect(function(input, gpe)
	if gpe then return end
    if input.KeyCode == Enum.Keycode.Q then
    -- Create object via remote event.
    end
end)

Edit: Make sure you define UserInputService

1 Like

Thank you very much! I appreciate the help!

Put ``` before and after the code (on its own line) so that the devforum recognizes it as code. It’ll make it much easier to read and debug.

1 Like