Basically, I want it so when you press M, it spawns a wall, 10 studs in front of the player and in the direction that the player is facing. But it wont work!
function KeyDown(Key) KeyHolding = true if Key == "m" then Wall() if Key == "n" then Nuke() end end end function Wall() local Wall = Instance.new("Part",game.Workspace) Wall.Position = CFrame.new(Torso.CFrame.x,0,Torso.CFrame.y) Wall.CFrame = CFrame.new(Torso.CFrame.x, Torso.CFrame.y, Torso.CFrame.z + 10) * math.rad(0,0,Head.CFrame.lookVector) -- Note that the head and torso has already been specified through variables in another line (not featured) wait(10) Wall:Destroy() end
Hi there, since you did not provide the full script, I just assumed some parts of it. The mistake you did was that you did not set the Size nor the Anchor Property if your Part. The next issue you have, is that you tried to multiply a CFrame with a number (math.rad returns a number in radians.)
There is a Devforum Thread which is about "How to make a part spawn infront of a player" (Click me to go there).
Here is your wall function which should work with comments on what does what.
function Wall() local Wall = Instance.new("Part") -- Create a new Part Object Wall.Parent = workspace -- Parent it to workspace Wall.Size = Vector3.new(10, 10, 1) -- Set it's size to 10x10x1 Wall.Anchored = true -- Anchor it so it does not fall Wall.CFrame = Torso.CFrame * CFrame.new(0, 0, -10) -- Place it 10 studs infront of the character wait(10) -- Wait 10 seconds Wall:Destroy() -- Destroy the Part end
Hope that could help you!