local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local function onInputBegan(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
if keyPressed == Enum.KeyCode.LeftShift then
game.Workspace.Meshpart = Torso
game.Workspace.Particles = Torso
end
end
end
UserInputService.InputBegan:connect(onInputBegan)
How do you make something attach to the torso when you press a key?
1 answer
Next time, be sure to code block if you don't know how it's on top of of your text editor when you paste something as a question on the website.
Now by implying by your code I'm assuming you wanted to attach the Mesh and Particles?
This is your code
local UserInputService = game:GetService("UserInputService") local localPlayer = game.Players.LocalPlayer
local function onInputBegan(input, gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then local keyPressed = input.KeyCode if keyPressed == Enum.KeyCode.LeftShift then game.Workspace.Meshpart = Torso game.Workspace.Particles = Torso
end end end
UserInputService.InputBegan:connect(onInputBegan)
This is the edited/corrected version
--Always remember to indent your code so it can be easier to read.
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local Torso = localPlayer.Character.Torso --The Torso variable you probably forgot to make.
local function onInputBegan(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
if keyPressed == Enum.KeyCode.LeftShift then
--Add some welds
local w = Instance.new("Weld",localPlayer.Character)
w.Part0=game.Workspace.Meshpart --We weld the Meshpart to the part0 property.
w.Part1=Torso --Take it to the Torso variable.
w.C0=CFrame.fromEulerAnglesXYZ(0,0,0)*CFrame.new(0,5,0) --CFrame it to adjust the positioning
while welded
Instance.new("ParticleEmitter",Torso) --Instance the particleemitter on the characters Torso.
end end end
UserInputService.InputBegan:connect(onInputBegan)
These are your mistakes
game.Workspace.Meshpart = Torso game.Workspace.Particles = Torso
Torso
Firstly, you can't just directly take things and try to parent them like that you would need to weld the Meshpart.
And secondly you can't put particleemitters on by just directly taking it by an equal.
You would need to instance the particleemitter since it cannot be welded.
Always indent your code so that it may be easier to read.
Torso wouldn't be valid unless it was a variable.
Hope this helped, don't forget to accept or upvote if it did.
1 comment
Nice answer
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Please use CodeBlock