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

How do i press a key and a part spawns "right in front of me" (Front) ?

Hi I'm just wondering if there is a way that I can just press the "t" key and a part spawns right in front of me.

2 comments

0

just a new part just spawnin "in front of me?

0

This is a site called "Scripting Helpers", not "Script Requesters". Please Attempt on doing the script first instead of Just asking someone else to do it for you.

2 answers

✓ Accepted answer

I would read up on the User Input Service, which handles keystrokes, and any other input types

https://wiki.roblox.com/index.php?title=API:Class/UserInputService

If it's Filtering Enabled then I suggest using a RemoteFunction to talk to a Server Script where it spawns the part relative to the players character. You can also pass the players characters location.

https://wiki.roblox.com/index.php?title=API:Class/RemoteFunction

http://wiki.roblox.com/index.php?title=API:Class/Player

If FilteringEnabled is disabled, then you can just use the players location and spawn the brick relative to the player's character.

Next time, please make an attempt at the problem by doing research on what you'd like, start by simple searches like "How to make keybinds in roblox", it will go a long way. A lot of programming is done through research, so make a habit of doing it.

Hope this helps, good luck!

1 comment

0

but how do i spawn it in front of the player not in the player...and i all ready know hao to do the key stuff

The LOCAL SCRIPT must be inside the StarterPack and a Vector3Value must be insied the script, named DIR.

local plyr = game.Players.LocalPlayer
local char = game.Workspace:WaitForChild(plyr.Name)
local Mouse = plyr:GetMouse()
Mouse.KeyDown:Connect(function(key)
	if key == "r" then
		local p = Instance.new("Part",game.Workspace)
		script.DIR.Value = char.Humanoid.MoveDirection
		p.CFrame = CFrame.new(char.Head.Position + script.DIR.Value)
	end
end)

This will spawn a part in front of the Player. This does not work with keys like Shift Space, and Caps. But it works with the alphabet.

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