I have this script that lets you move a part (If it's name is Pizza) to wherever you want. I was testing some stuff in the game and I just realized that the script sometimes works and sometimes doesn't? Is there anyway I could make this script work every time instead of just sometimes? (The script is a local script located in game.StarterPack) Sometimes the script works very well and sometimes it only works for the client.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local point
local down
function clickObject()
if mouse.Target ~= nil then
if mouse.Target.Name == "Pizza" then
point = mouse.Target
mouse.TargetFilter = point
down = true
end
end
end
mouse.Button1Down:Connect(clickObject)
function moveMouse()
if down and point then
local posX, posY, posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z
posX = (posX + 0.5) - (posX + 0.5) % 1
posY = (posY + 0.5) - (posY + 0.5) % 1
posZ = (posZ + 0.5) - (posZ + 0.5) % 1
point.Position = Vector3.new(posX,posY,posZ)
end
end
mouse.Move:Connect(moveMouse)
function mouseDown()
down = false
point = nil
mouse.TargetFilter = nil
end
mouse.Button1Up:Connect(mouseDown)
someone please show me what I'm doing wrong!

3 comments
You should be using a remote event or a remote function if you're going to do this in a filtering enabled game.
Works for me
It works for server and client sometimes but sometimes it only works for client