How would I make this script work for models instead of just 1 part?
Asked by
6 years ago Edited 6 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):
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
07 | if mouse.Target ~ = nil then |
08 | if mouse.Target.Parent.Name = = "Crate" then |
10 | mouse.TargetFilter = point |
15 | mouse.Button 1 Down:Connect(clickObject) |
18 | local posX, posY, posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z |
19 | posX = (posX + 0.5 ) - (posX + 0.5 ) % 1 |
20 | posY = (posY + 0.5 ) - (posY + 0.5 ) % 1 |
21 | posZ = (posZ + 0.5 ) - (posZ + 0.5 ) % 1 |
22 | point.Position = Vector 3. new(posX,posY,posZ) |
25 | mouse.Move:Connect(moveMouse) |
29 | mouse.TargetFilter = nil |
31 | mouse.Button 1 Up:Connect(mouseDown) |
When I tried to make it move the entire model I tried this:
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
07 | if mouse.Target ~ = nil then |
08 | if mouse.Target.Parent.Name = = "Crate" then |
10 | mouse.TargetFilter = point |
15 | mouse.Button 1 Down:Connect(clickObject) |
18 | local posX, posY, posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z |
19 | posX = (posX + 0.5 ) - (posX + 0.5 ) % 1 |
20 | posY = (posY + 0.5 ) - (posY + 0.5 ) % 1 |
21 | posZ = (posZ + 0.5 ) - (posZ + 0.5 ) % 1 |
22 | local model = point.Parent |
23 | model:MoveTo(Vector 3. new(posX,posY,posZ)) |
26 | mouse.Move:Connect(moveMouse) |
30 | mouse.TargetFilter = nil |
32 | mouse.Button 1 Up: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?