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 8 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

h                   = script.Parent.Humanoid

t                   = script.Parent.Torso

while wait(1.5) do

local p                 = Instance.new("Part")

p.CanCollide        = false

p.Transparency       = 1

p.Anchored      = true

p.Position           = t.Position + Vector3.new(math.random(-50,50),0,math.random(-10,10))

p.Parent             = script.Parent

h:MoveTo(Vector3.new(p.Position.X,p.Position.Y,p.Position.Z))

wait(math.random(2,3))

p:remove()

end

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 — 8y
0
He means add whitespace: http://wiki.roblox.com/index.php?title=Whitespace EgoMoose 802 — 8y
0
what kind of whitespace is that LegitimatlyMe 519 — 8y

1 answer

Log in to vote
4
Answered by
EgoMoose 802 Moderation Voter
8 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:

-- unless stated otherwise using the same variables you did.
local head = script.Parent.Head;
local weld = Instance.new("Weld", t);
weld.Name = "Neck";
weld.Part0 = t;
weld.Part1 = head;
weld.C0 = t.CFrame:inverse() * head.CFrame;

-- you might need to loop this assuming your bear isn't two parts.
t.Anchored = false;
head.Anchored = false;

As for properly white spaced code:

h = script.Parent.Humanoid
t = script.Parent.Torso

while wait(1.5) do
    local p = Instance.new("Part")
    p.CanCollide = false
    p.Transparency = 1
    p.Anchored = true
    p.Position = t.Position + Vector3.new(math.random(-50,50),0,math.random(-10,10))
    p.Parent = script.Parent
    h:MoveTo(Vector3.new(p.Position.X,p.Position.Y,p.Position.Z))
    wait(math.random(2,3))
    p:remove()
end
0
Great answer. It would look much more pretty with inline code and some emboldened areas. User#11440 120 — 8y
Ad

Answer this question