Regarding the game im developing right now with a dragging system i scripted myself. The system itself works fine, but when the player lets go, the parts are supposed to stick to the nearest surface, but when doing so they can also clip in the nearest surface.
If i didn’t explain it clearly, here is a video:
robloxapp-20241102-0858276.wmv (2.9 MB)
And here are the two scripts responsible for the dragging system:
local script:
-- var defining 1
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local RS = game:GetService("ReplicatedStorage")
-- var defining 2
local selBlock
local dragBall
-- var defining 3
local dragging = false
-- inputbegan block (what happens when the player is attempting to drag a block)
UIS.InputBegan:Connect(function(input)
if mouse.Button1Down and input.UserInputType == Enum.UserInputType.MouseButton1 and mouse.Target ~= nil and mouse.Target:HasTag("draggable") then
selBlock = mouse.Target
print(mouse.Target)
if mouse.Target:IsA("BasePart") or mouse.Target:IsA("Mesh") or mouse.Target:IsA("UnionOperation") then
dragging = true
mouse.TargetFilter = selBlock
-- what happens when the block is being dragged
-- visuals set up in server script
RS.VisualSet:FireServer(selBlock)
while dragging == true do
task.wait()
local ASHV = mouse.Hit
RS.ReplicateHit:FireServer(ASHV)
end
end
end
end)
--inputended block (what happens when the player is no longer dragging a block)
UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and mouse.Button1Up and dragging == true then
dragging = false
mouse.TargetFilter = nil
selBlock = nil
end
end)
--rotation block
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
RS.RotationHit:FireServer()
print("rotate fired")
end
end)
server script:
local dragBall
local selBlock2
local orient
local RS = game.ReplicatedStorage
RS.VisualSet.OnServerEvent:Connect(function(plr, selBlock)
selBlock2 = selBlock
selBlock2.Anchored = true
selBlock.CanCollide = true
orient = Vector3.new(0, 0, 0)
selBlock2.Orientation = orient
end)
RS.ReplicateHit.OnServerEvent:Connect(function(plr, ASHV)
script.MouseHit.Value = ASHV
selBlock2.CFrame = script.MouseHit.Value
selBlock2.Orientation = orient
end)
RS.RotationHit.OnServerEvent:Connect(function(plr)
orient = orient + Vector3.new(0, 45, 0)
print(selBlock2.Orientation)
end)
Also for anyone who wants to see the bug in person here is the game Hold It Simulator: A New Shine - Roblox