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

Why wont this model move?

Asked by 9 years ago

Problem: I have this model of a bear, I put this script in the model so that it will move randomly,but it dosen't move at all. Pls Halp D:

Script

01h                   = script.Parent.Humanoid
02 
03t                   = script.Parent.Torso
04 
05while wait(1.5) do
06 
07local p                 = Instance.new("Part")
08 
09p.CanCollide        = false
10 
11p.Transparency       = 1
12 
13p.Anchored      = true
14 
15p.Position           = t.Position + Vector3.new(math.random(-50,50),0,math.random(-10,10))
View all 25 lines...

PS: How would i add an animation to the model, like a walking annimation, I already have the animation just dont know how to add it, pls put that in your answe if you know how .w.

0
what do you mean TheTermaninator 45 — 9y
0
He means add whitespace: http://wiki.roblox.com/index.php?title=Whitespace EgoMoose 802 — 9y
0
what kind of whitespace is that LegitimatlyMe 519 — 9y

1 answer

Log in to vote
4
Answered by
EgoMoose 802 Moderation Voter
9 years ago

Alright, so here's the good news, there's nothing wrong with your code (aside from the whitespace). I'm pretty sure the problem you're having is that your bear either doesn't have a part named "Head" or, if it does it's not welded to the torso by a joint named "Neck".

As such you're going to have to do that. The rule of thumb when it comes to joints is:

weld.Part0.CFrame * C0 == weld.Part1.CFrame * C1

As such you can rearrange to easily find C0 or C1. For your case we'll keep things simple and assume C1 is CFrame.new() which is essentially the identity CFrame and we can pretend like it's not there (eg. It's like multiplying by 1).

So solving for C0 to have a weld maintain two parts relative position:

C0 = weld.Part0.CFrame:inverse() * weld.Part1.CFrame

Remember the joint needs to have the name "Neck" and must be parented under the "Torso" part.

Here's an example, although personally I recommend doing the weld beforehand as opposed to generating it as the game starts because then you can avoid all that anchoring business:

01-- unless stated otherwise using the same variables you did.
02local head = script.Parent.Head;
03local weld = Instance.new("Weld", t);
04weld.Name = "Neck";
05weld.Part0 = t;
06weld.Part1 = head;
07weld.C0 = t.CFrame:inverse() * head.CFrame;
08 
09-- you might need to loop this assuming your bear isn't two parts.
10t.Anchored = false;
11head.Anchored = false;

As for properly white spaced code:

01h = script.Parent.Humanoid
02t = script.Parent.Torso
03 
04while wait(1.5) do
05    local p = Instance.new("Part")
06    p.CanCollide = false
07    p.Transparency = 1
08    p.Anchored = true
09    p.Position = t.Position + Vector3.new(math.random(-50,50),0,math.random(-10,10))
10    p.Parent = script.Parent
11    h:MoveTo(Vector3.new(p.Position.X,p.Position.Y,p.Position.Z))
12    wait(math.random(2,3))
13    p:remove()
14end
0
Great answer. It would look much more pretty with inline code and some emboldened areas. User#11440 120 — 9y
Ad

Answer this question