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
01 | wait() |
02 | local npc = game.Workspace.House 1. NPC -- Needs Fixing |
03 | local doorbell = game.Workspace.House 1. Doorbell |
04 | local dbs = game.ServerStorage.Sounds.Doorbell_Sound |
05 | local Window = game.Workspace.House 1. Windows |
06 | deb = true |
07 | script.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(Vector 3. new(- 38.4 , 4.5 , 18.8 )) -- Want NPC to teleport here (Outside House) |
15 | wait( 5 ) |
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.
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
01 | local Part = Workspace.Part -- this is the Part we will move |
02 | local newPos = Part.Position + Vector 3. new( 0 , 5 , 0 ) -- the position the Part will go to |
03 | local Time = 10 -- the time that the script will take to move the part |
04 | local Increment = 0.5 -- the Part will move 0.5 studs each time it moves |
05 | local Debounce = false |
06 |
07 | local Diff = newPos - Part.Position -- the difference between the two positions |
08 | local Mag = Diff.magnitude -- the distance between the two parts |
09 | local Direction = CFrame.new(Part.Position, newPos).lookVector |
10 |
11 | function 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) |
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)
1 | local RnewPos = Part.Position + Vector 3. new( 0 ,- 5 , 0 ) -- The Inverse position of newPos |
2 | local RDiff = RnewPos - Part.Position -- the difference between the two positions |
3 | local RMag = RDiff.magnitude -- the distance between the two parts |
4 | local RDirection = CFrame.new(Part.Position, RnewPos).lookVector |
(insert under MovePart()
1 | function 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 |
9 | end |