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

Placing Script Not Placing Properly?

Asked by 8 years ago

Before We begin here are some things you should know the Heirarchy

Problem: The following script does everything it is saposed to do, but when the part if following the mouse, and when I finally place it, it does not place right It looks like this , although i want to be placed like this , Also if i leave the mouse still while I'm in placing mode, the item will get closer and closer

Script

local cam = game.Workspace.CurrentCamera
local Item = game.ReplicatedStorage.Building.Walls.WoodenWall
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local enabled = script.Parent.Enabled
local amount = script.Parent.Amount
local Placing = false


script.Parent.MouseButton1Down:connect(function()

if enabled.Value == true then
    enabled.Value = false
elseif enabled.Value == false then  
    enabled.Value = true
    end
if Placing == true then
    local Item2 = cam:WaitForChild('WoodenWall')
    local Torso = game.Workspace:WaitForChild(player.Name).Torso
    local mag = (Item2.Position - Torso.Position).magnitude
    print(mag)
    if mag <= 40 then
    Item2:WaitForChild('bob'):remove()
    Item2.Parent = game.Workspace
    Item2.CFrame = mouse.Hit + Vector3.new(0, 50, 0)
    Item2.CanCollide = true
    Placing = false
    enabled.Value = false
    amount.Value = amount.Value - 1
end
end
end)

script.Parent.MouseButton2Down:connect(function()
    if enabled.Value == true and amount.Value >= 1 then

        local Item2 = Item:Clone()
        Item2.Parent = cam
        local selectionBox = Instance.new("SelectionBox",Item2) --We set its parent, but not where it's going to overlay
        selectionBox.Adornee = Item2 
        selectionBox.Name = 'bob'
        selectionBox.Color = BrickColor.new("Lime green")
        Placing = true





        repeat
            wait(.1)
        Item2.CFrame = mouse.Hit
        until enabled.Value == false or amount.Value < 1        
    end

end)

2 answers

Log in to vote
1
Answered by
Unlimitus 120
8 years ago

Change line 25 to mouse.Hit.p, which returns position only. mouse.Hit is a CFrame and CFrame has rotation values included.

Ad
Log in to vote
0
Answered by 8 years ago

The reason the part gets closer when you leave it still is because it's pointing at the object and it is moving to the mouse's position. You'd need to set the mouse's target filter to the model you're wanting to place

0
how do i use target fitler TheTermaninator 45 — 8y

Answer this question