My code is requiring that players click on the cube once before they click and drag to position the cube. The desired behavior is to simply click-and-drag.
UserInputService.InputBegan:Connect(function(key, isSystemReserved)
local part = mouse.Target
mouse.TargetFilter = part
if part then
if part.Name == "cube" then
guide.Transparency = 0.7
while UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
local mousePosition = mouse.Hit.p
if mousePosition.X > constraintLeft.X and mousePosition.X < constraintRight.X then
part.Position = Vector3.new(mousePosition.X, part.Position.Y, part.Position.Z)
guide.Position = Vector3.new(mousePosition.X, guide.Position.Y, guide.Position.Z)
end
RunService.RenderStepped:Wait()
end
guide.Transparency = 1
launchCubeEvent:FireServer(part.CFrame)
end
end
end)
The test version of the game with the issue is located here.