Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Mr_Unlucky 1085 Moderation Voter
6 years ago

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
0
Did you bind the "KeyDown" function? And if possible, send the entire code. NurZwanzigBuchstaben 50 — 6y
0
it works but the wall part just spawns a normal part. Mr_Unlucky 1085 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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!

0
Thanks so much! Mr_Unlucky 1085 — 6y
0
Might as well mark this as solution if it actually works NurZwanzigBuchstaben 50 — 6y
Ad

Answer this question