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

How would I make this script work for models instead of just 1 part?

Asked by 5 years ago
Edited 5 years ago

I have a moving system that lets you move crates (Made Of Just 1 Part) around and snaps to 1 stud (script is a local script located in game.StarterPack):

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local point 
local down

function clickObject()
if mouse.Target ~= nil then
if mouse.Target.Parent.Name == "Crate" 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)

When I tried to make it move the entire model I tried this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local point 
local down

function clickObject()
if mouse.Target ~= nil then
if mouse.Target.Parent.Name == "Crate" 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
local model = point.Parent
model:MoveTo(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)

But when I use the new script it seems very glitchy because the crate teleports back and fourth, Could someone show me how make the first script move the entire crate model with out it teleporting back and fourth?

0
Not really an answer but try using SetPrimaryPartCFrame instead to avoid collisions. Asentis 17 — 5y

Answer this question