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)