Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My wall script wont spawn walls in front of the player like it's supposed to, but why not?

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

2 comments

0

Did you bind the "KeyDown" function? And if possible, send the entire code.

0

it works but the wall part just spawns a normal part.

1 answer

✓ Accepted answer

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!

2 comments

0

Thanks so much!

0

Might as well mark this as solution if it actually works

This discussion is preserved as it was. New answers, comments, and votes are closed.