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

How can I move a model when I click an object?

Asked by 8 years ago

When I ring the doorbell I want my NPC to be able to change the position to the ones I have in the code but this isn't working. I think I need to use the Torso, however the NPC is just a model without a humanoid so I would need to move the whole model. << Probably overthinking this as well

01wait()
02local npc = game.Workspace.House1.NPC -- Needs Fixing
03local doorbell = game.Workspace.House1.Doorbell
04local dbs = game.ServerStorage.Sounds.Doorbell_Sound
05local Window = game.Workspace.House1.Windows
06deb = true
07script.Parent.Doorbell.ClickDetector.MouseClick:connect(function(wat)
08    if deb == true then
09        deb = false
10            dbs:Play()
11            Window.BrickColor = BrickColor.new("Bright yellow")
12            Window.Transparency = .45
13            Window.Material = "Neon"
14            npc.CFrame = CFrame.new(Vector3.new(-38.4, 4.5, 18.8)) -- Want NPC to teleport here (Outside House)
15            wait(5)
View all 22 lines...
1
You would need to use npc.Torso.CFrame, not npc.CFrame. nilVector 812 — 8y
0
Also, you don't need to give a vector to a CFrame. You can just give the numbers directly. GoldenPhysics 474 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

As far as I know, you have to script all the parts inside the NPC to go to their respective locations. If your NPC is a Humanoid tho, you can probably just set the torso's CFrame and all the limbs would go along. Probably, I don't know.

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

The way I move blocks is by Part Sliding

I have been working on a Factory Tycoon type game and I have recently figured out how to move a block through any activation methods such as Click or Touch (there are plenty more but we'll keep this simple)

In order to make a block move due to click you need: 1. A part you want to move 2. A block you will use that will activate the function

01local Part = Workspace.Part -- this is the Part we will move
02local newPos = Part.Position + Vector3.new(0,5,0) -- the position the Part will go to
03local Time = 10 -- the time that the script will take to move the part
04local Increment = 0.5 -- the Part will move 0.5 studs each time it moves
05local Debounce = false
06 
07local Diff = newPos - Part.Position -- the difference between the two positions
08local Mag = Diff.magnitude -- the distance between the two parts
09local Direction = CFrame.new(Part.Position, newPos).lookVector
10 
11function MovePart() -- function to move the Part
12    if Debounce then return end -- end the function if debounce is true
13    Debounce = true -- make Debounce true so the function can't run
14    for n = 0, Mag, Increment do
15        Part.CFrame = Part.CFrame + (Direction * Increment)
View all 25 lines...

Along with that I had created the inverse of the local variables presented in the beginning of the script and made a new function to RESET PART POSITION: (insert under other local variables stated in beginning of script)

1local RnewPos = Part.Position + Vector3.new(0,-5,0) -- The Inverse position of newPos
2 local RDiff = RnewPos - Part.Position -- the difference between the two positions
3local RMag = RDiff.magnitude -- the distance between the two parts
4local RDirection = CFrame.new(Part.Position, RnewPos).lookVector

(insert under MovePart()

1function ResetPart() -- function to reset the Part to its original position
2    if Debounce then return end -- end the function if debounce is true
3    Debounce = true -- make Debounce true so the function can't run
4    for n = 0, RMag, Increment do
5        Part.CFrame = Part.CFrame + (RDirection * Increment)
6        wait( (Time/RMag) * Increment )
7    end
8    Debounce = false -- set Debounce to false so the function can run again
9end
0
Sorry if its a bit to read x) but you know, i'd rather over explain it than leave things unexplained gocrazyeveryone 0 — 8y
0
ALSO: Referring to your problem with moving an NPC, if you have it grouped together you can replace " line 1: Local Part = workspace.Part " with one that moves your grouped parts to be "line1: local Part = workspace.NPC gocrazyeveryone 0 — 8y

Answer this question