Building system is flying

Why is my building system selection buggy?
robloxapp-20210903-1937525.wmv (161.6 KB)
Its flying idk why

The script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local selection = Instance.new("Part",workspace)
selection.Size = Vector3.new(0.5,0.5,0.5)
selection.CanCollide = false
selection.Anchored = true
selection.Shape = Enum.PartType.Ball
selection.BrickColor = BrickColor.new("Grey")
local context = game:GetService("ContextActionService")

local function changeselection()
    local raycast = workspace:Raycast(mouse.Hit.Position + Vector3.new(0,5,0),Vector3.new(0,-150,0))
    if raycast ~= nil then
        if raycast.Instance == game.Workspace.Baseplate then
            selection.Position = Vector3.new(mouse.Hit.Position.X,raycast.Position.Y,mouse.Hit.Position.Z) + Vector3.new(0,selection.Size.Y/2,0)
        elseif raycast.Instance ~= game.Workspace.Baseplate and raycast.Instance:IsA("Part") then
            selection.Position = Vector3.new(mouse.Hit.Position.X,raycast.Position.Y,mouse.Hit.Position.Z) + Vector3.new(0,selection.Size.Y/2,0)
        end
    end
end

context:BindAction("ChangeSelection",changeselection,false,Enum.UserInputType.MouseMovement)

Your mouse is hitting the selection part causing it go up. You need to blacklist the selection part

1 Like

This happens because the raycast is not ignoring the selection ball. Try adding parameters to the raycast and blacklist the ball and the character.

you mean white list? or black list

Blacklist is for ignoring certain parts, whitelist is for ignoring other parts except certain parts