Im trying to make a block spawn infront of the player. So basically I want to use the keyboard to make some sort of spell and shortcut. I was wondering why it doesn't work please help. Problem is with the code because when i press it nothing spawns
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 Part = Instance.new("Part")
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)

8 comments
Do you use R15 when testing this script? “Torso” can only be found in R6 characters, so try “HumanoidRootPart” instead. Also, creating a part then cloning it really isn’t necessary, just use the part you created instead of cloning it.
Im using R6 characters
Okay...is this a local script or a server (normal) script? Also, where is the script located?
Server script and its located in workspace
Oh, that’s why. Server scripts can’t use LocalPlayer and other local stuff like UserInputService. You must do that in a local script, and the local script has to be placed in certain places like StarterGui for it to work. You could copy all your code into a local script and it should work, but it would only show for you I think.
By the way, if you want the part to show for everyone, you would have to use remote events. Here’s a tutorial on how to use it : https://developer.roblox.com/articles/Remote-Functions-and-Events
Changed it to a local doesnt work
Yeah, local scripts won't run in the Workspace.