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

How to I make a brick appear in front of me where ever I'm standing using instance.New() ?

Asked by 7 years ago

I'm trying to make a brick appear in front of me where ever I'm standing in any direction. Not sure really where to go. But I do have this much done.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

function MakeBrick()
    local c = Instance.new("Part")
    c.BrickColor = BrickColor.new("Bright blue")
    c.Transparency = 0.5
    c.TopSurface = "SmoothNoOutlines"
    c.BottomSurface ="SmoothNoOutlines"
    c.Size = Vector3.new(29.13, 15.9, 2)


    c.Parent = game.Workspace   

    wait(1)
    c:Destroy()
end


mouse.KeyDown:connect(function(key)
    if key == "e" then
        MakeBrick()
    end
end)

it's inside a local script in the "Backpack" of the player so it should work. If anyone could help that would be awesome!

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago

You can set its CFrame using the CFrame of the LocalPlayer's Character's Torso + lookVector:

c.CFrame = player.Character.Torso.CFrame + player.Character.Torso.CFrame.lookVector*5
Ad
Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You can simply reference your character's CFrame and go from there :)

--Reference character's CFrame
c.CFrame = player.Character:GetPrimaryPartCFrame()
         * CFrame.new(0,0,-5)  --Move out 5 units
         * CFrame.new(0,0,-c.Size.Z/2) --Take size into account

Answer this question