`
local Part = game.Workspace.Test
local DropperPart = player.Charecter:WaitForChild('Torso')
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then -- Checks if the input was related to a keyboard
if input.KeyCode == Enum.KeyCode.Q then
if player.Charecter then
local torso = player.Charecter:WaitForChild('Torso')
local NewPart = Part:Clone()
NewPart.Parent = torso
NewPart.CFrame = torso.CFrame
game:GetService('Debris'):AddItem(NewPart,3)
end
end
end
end)`
Heres my code I am trying to figure out what is wrong with it
Yes it is possible. If you create two parts, one named a
and another b
, and run this code in command bar, workspace.b.CFrame = workspace.a.CFrame + workspace.a.CFrame.LookVector * 10
, it will work.
To fix your code, to not only do this but actually work because I've spotted multiple errors in it, here you go.
local Part = game.Workspace.Test local Players = game:GetService("Players") local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Keyboard then -- Checks if the input was related to a keyboard if input.KeyCode == Enum.KeyCode.Q then if Players.LocalPlayer.Character then local torso = Players.LocalPlayer.Character:WaitForChild("Torso") local NewPart = Part:Clone() NewPart.Parent = torso NewPart.CFrame = torso.CFrame + torso.CFrame.LookVector * 10 --10 is the distance, in studs NewPart will be away from torso game:GetService("Debris"):AddItem(NewPart,3) end end end end)
Hopefully this works.