I have a drag object script that I use. I am coding a box that if I drag a specific item and hit that box then it should teleport to a location. The issue I have is that if the player continues to hold onto the item and doesn’t let go of their mouse, the item starts glitching from that initial spot to their cursor. Can I run a remote event from that box’s code into the drag script that forces the player to let go of their mouse?
The first thing you should probably do is look into the reason its glitching. Hackfixes decrease the quality of your programming.
Consider posting the script here, and we could help you with that.
Here is the code. Not sure if this matters, I am trying to have the player drag an object through this script to hit a server scripted box. After it hits I want to player to let go of the initial object but unless I can find a way to force the player to release their mouse I am not sure how to approach it
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local target
local down
game:GetService("RunService").RenderStepped:Connect(function()
if down == true and target ~= nil then
target.Gyro.CFrame = target.CFrame
target.Force.Position = camera.CFrame.Position + (mouse.UnitRay.Direction * 10)
end
end)
mouse.Button1Down:connect(function()
if mouse.Target ~= nil and mouse.Target.Locked == false and mouse.Target == workspace.Pizza.Grab then
target = mouse.Target
mouse.TargetFilter = target
down = true
local gyro = Instance.new("BodyGyro")
gyro.Name = "Gyro"
gyro.Parent = target
gyro.MaxTorque = Vector3.new(350000, 350000, 350000)
local force = Instance.new("BodyPosition")
force.Name = "Force"
force.Parent = target
force.MaxForce = Vector3.new(10000, 10000, 10000)
end
end)
mouse.Button1Up:connect(function()
if target then
if target:FindFirstChild("Gyro") or target:FindFirstChild("Force") then
target.Gyro:Destroy()
target.Force:Destroy()
end
end
down = false
mouse.TargetFilter = nil
end)
It could be conflicting with the server position. While you are testing, try clicking the Current: Client
button on the top bar to switch to server view.
Also, you could just have the function bound to something else as well/ instead, like just waiting a few seconds after detected movement, say if there’s no movement of the cursor within 2.5 seconds, it will fire the function.