Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mouse To Move Part Script Only Works Sometimes?

Asked by 5 years ago

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!

0
You should be using a remote event or a remote function if you're going to do this in a filtering enabled game. maxbd 44 — 5y
0
Works for me ihatecars100 502 — 5y
0
It works for server and client sometimes but sometimes it only works for client kizi3000 88 — 5y

Answer this question