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

Placing script moves the object but the object is not all the way above the ground or base?

Asked by
LuaDLL 253 Moderation Voter
4 years ago
Edited by User#24403 4 years ago

GIF of moving: Moving

Pic Of Object: Object

Script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(0.5)
local Rs = game:GetService("RunService")
local Hb = Rs.Heartbeat

function getBaseFromPlayer(Player)
    for i,v in pairs(workspace.Bases:GetChildren()) do
        local Info = v.Info
        local Owner = Info.Owner
        if Owner.Value ==  Player then
            return v
        end
    end
end

function MoveObj(Position, Obj)
    Obj:SetPrimaryPartCFrame(CFrame.new(Position.X, 1, Position.Z))
end

function StartPlacing(Obj)
    local ObjClone = Obj:Clone()
    ObjClone.Parent = workspace.CurrentCamera
    for i,v in pairs(ObjClone:GetChildren()) do
        if v:IsA("BasePart") and v.Name ~= "Hitbox" then
            v.Transparency = 0.5
            v.CanCollide = false
        end
    end
    return ObjClone
end

local Obj = game:GetService("ReplicatedStorage"):WaitForChild("Items").TestModel
local PlacingItem = StartPlacing(Obj)
Hb:Connect(function()
    MoveObj(Mouse.hit.p, PlacingItem)
end)

1 answer

Log in to vote
0
Answered by 4 years ago

The problem is probably that the mouse doesn't ignore the object you're trying to place. Just add this little snippet of code to your script.

Mouse.TargetFilter = ObjClone
Ad

Answer this question