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

How do i make it so f makes a part spawn?

Asked by 6 years ago

Hi, I'm new to scripting and I want to make it so when you press F, a model appears behind the player. Can someone please help?

1 answer

Log in to vote
0
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago
Edited 6 years ago

Hi, to accomplish this, you will need to get use to using the UserInputService since keyDown is deprecated. Here's an example

local UIS = game:GetService("UserInputService")
local p = game.Players.LocalPlayer
debounce = false

UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
local KeyCode = Input.KeyCode -- creates a value called KeyCode for future use
if not gameProcessedEvent then -- checks if the player ISN'T TYPING

if KeyCode == Enum.KeyCode.F and debounce == false then
debounce = true -- prevents it from being ran over and over again
local newPart = Instance.new("Part", workspace) -- change `workspace` to where you want the part to be parented to
newPart.Name == "IMadeANewPart!" -- change that to your part's name
--Also use the properties to set how the part will look. For ex:
newPart.Size = Vector3.new(0, 0, 0) -- change 0, 0, 0 depending on the X, Y, & Z Sizing 
newPart.CanCollide = false -- determines if the block is walkthrough
newPart.Transparency = 0 -- change that to how transparent you want the block to be
newPart.Shpae == "" -- use the properties tab on the brick to set the shape
newPart.CFrame = p.Character.Torso.CFrame * CFrame.new(0, 0, 0) -- once again change 0, 0, 0 depending on the X, Y, & Z's Position this time. Since you want it behind, i would suggest changing the X or the Z's coordinates, i forgot which one goes back and fourth. Also change `Torso` to either `UpperTorso` or `LowerTorso` depending on if the character is R15
end
end
end)

--Also if you want the script to be ran again, put debounce = true if at the end if you want the script to be ran again

Any more questions, please feel free to ask!

--oSy

0
Thank you very much! Where do i put the script? olasean268 0 — 6y
0
A localscript in starterpack, and make sure to accept the answer oSyM8V3N 429 — 6y
Ad

Answer this question