How to use UserInputService to spawn a block

So I wanna make an anime game, and I was testing out the move “Room” which basically spawns a blue circle around you. My question is how do I use UserInputService to spawn a block around my character.

You don’t use UserInputService to spawn parts. The service is used to detect key presses & etc. If you read the documentation on Roblox’s website, you will be able to figure out your goal. Creating a part involves using the function Instance.new, let me know if you need help with anything else.

Thanks for replying, I was thinking of using UserInputService to press a key in which it then spawns a part on my character using instance. Sorry if I’m not being clear, I am a complete beginner in scripting

Probably use RbxMouse or built-in legacy Mouse, there are many tutorials on devforum how to make Building system.

You would first set up a UserInputService within a Local Script that would listen to your input. Lets say you chose the key “H”.

local uis = game:GetService(“UserInputService”)

uis.InputBegan:connect(function(input, gpe)
    if input.KeyCode == Enum.KeyCode.H then

    end
end)

Then you would need to connect a remote event within this event to create the part. Assuming you have a Remote Event called “RemoteEvent” in Replicated Storage:

local uis = game:GetService(“UserInputService”)
local re = game:GetService(“ReplicatedStorage”):WaitForChild(“RemoteEvent”)

uis.InputBegan:connect(function(input, gpe)
    if input.KeyCode == Enum.KeyCode.H then
        re:FireServer()
    end
end)

Within a script, we would need to listen for this call to create your part.

local re = game:GetService(“ReplicatedStorage”):WaitForChild(“RemoteEvent”)

local function createPart(player)
    local Part = Instance.new(“Part”)
    Part.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -10)
    Part.Anchored = true
    Part.Parent = game.Workspace
end

re.OnServerEvent:connect(createPart)

This should provide you with the basics to making your skill.

may be a few errors, no access to studio atm

1 Like