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

Help me move with my model?

Asked by
neoG457 315 Moderation Voter
9 years ago
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()


Mouse.KeyDown:connect(function(key)
if key == "p" then

local RinkakuModel = game.ReplicatedStorage.WorkspaceRinkakuModel:Clone() --Assuming the model is now in ReplicatedStorage
game.ReplicatedStorage.WorkspaceRinkakuModel.PrimaryPart = game.ReplicatedStorage.WorkspaceRinkakuModel.Primary


local   w = Instance.new('Weld')
w.Part0 = RinkakuModel.PrimaryPart
w.Part1 = Player.Character.Torso
w.Parent = RinkakuModel.PrimaryPart
w.C0 = CFrame.new(0, 10, 0)*CFrame.new(0, 0, 0)

local   w1 = Instance.new('Weld')
w1.Part0 = RinkakuModel.PrimaryPart
w1.Part1 = RinkakuModel.Part1
w.Parent = RinkakuModel.PrimaryPart


local   w2 = Instance.new('Weld')
w2.Part0 = RinkakuModel.PrimaryPart
w2.Part1 = RinkakuModel.Part2
w2.Parent = RinkakuModel.PrimaryPart


local   w3 = Instance.new('Weld')
w3.Part0 = RinkakuModel.PrimaryPart
w3.Part1 = RinkakuModel.Part3
w3.Parent = RinkakuModel.PrimaryPart


local   w4 = Instance.new('Weld')
w4.Part0 = RinkakuModel.PrimaryPart
w4.Part1 = RinkakuModel.Part4
w4.Parent = RinkakuModel.PrimaryPart


local   w5 = Instance.new('Weld')
w5.Part0 = RinkakuModel.PrimaryPart
w5.Part1 = RinkakuModel.Part5
w5.Parent = RinkakuModel.PrimaryPart


local   w15 = Instance.new('Weld')
w15.Part0 = RinkakuModel.PrimaryPart
w15.Part1 = RinkakuModel.Part6
w15.Parent = RinkakuModel.PrimaryPart

local   w6 = Instance.new('Weld')
w6.Part0 = RinkakuModel.PrimaryPart
w6.Part1 = RinkakuModel.Part7
w6.Parent = RinkakuModel.PrimaryPart


local   w7 = Instance.new('Weld')
w7.Part0 = RinkakuModel.PrimaryPart
w7.Part1 = RinkakuModel.Part8
w7.Parent = RinkakuModel.PrimaryPart


local   w8 = Instance.new('Weld')
w8.Part0 = RinkakuModel.PrimaryPart
w8.Part1 = RinkakuModel.Part9
w8.Parent = RinkakuModel.PrimaryPart


local   w9 = Instance.new('Weld')
w9.Part0 = RinkakuModel.PrimaryPart
w9.Part1 = RinkakuModel.Part10
w9.Parent = RinkakuModel.PrimaryPart


local   w10 = Instance.new('Weld')
w10.Part0 = RinkakuModel.PrimaryPart
w10.Part1 = RinkakuModel.Part11
w10.Parent = RinkakuModel.PrimaryPart


local   w11 = Instance.new('Weld')
w11.Part0 = RinkakuModel.PrimaryPart
w11.Part1 = RinkakuModel.Part12
w11.Parent = RinkakuModel.PrimaryPart

local   w12 = Instance.new('Weld')
w12.Part0 = RinkakuModel.PrimaryPart
w12.Part1 = RinkakuModel.Part13
w12.Parent = RinkakuModel.PrimaryPart


local   w13 = Instance.new('Weld')
w13.Part0 = RinkakuModel.PrimaryPart
w13.Part1 = RinkakuModel.Part14
w13.Parent = RinkakuModel.PrimaryPart


local   w14 = Instance.new('Weld')
w14.Part0 = RinkakuModel.PrimaryPart
w14.Part1 = RinkakuModel.Part15
w14.Parent = RinkakuModel.PrimaryPart



RinkakuModel.Part1.Anchored = true  
RinkakuModel.Part2.Anchored = true
RinkakuModel.Part3.Anchored = true
RinkakuModel.Part4.Anchored = true
RinkakuModel.Part5.Anchored = true
RinkakuModel.Part6.Anchored = true
RinkakuModel.Part7.Anchored = true
RinkakuModel.Part8.Anchored = true
RinkakuModel.Part9.Anchored = true
RinkakuModel.Part10.Anchored = true
RinkakuModel.Part11.Anchored = true
RinkakuModel.Part12.Anchored = true
RinkakuModel.Part13.Anchored = true
RinkakuModel.Part14.Anchored = true
RinkakuModel.Part15.Anchored = true
RinkakuModel.Primary.Anchored = true

RinkakuModel.Parent = workspace
RinkakuModel:SetPrimaryPartCFrame(Player.Character.Torso.CFrame*CFrame.new(0, 0, 0))
game.ReplicatedStorage.WorkspaceRinkakuModel:MakeJoints()
RinkakuModel:MakeJoints()
RinkakuModel.Name = Player.Name

end

    end)

All those are the parts inside RinkakuModel I need to They are welded to the PrimaryPart however they only stay in the right position if they are all anchored but when they are anchored I can not move with it. Could you help me keep it in the right position without having to anchor it?

For an example of what I'm trying to say go here:

http://www.roblox.com/games/226666043/Kagune-Making

0
Press P neoG457 315 — 9y

1 answer

Log in to vote
1
Answered by
noliCAIKS 210 Moderation Voter
9 years ago

You need to set the C0 or C1 to get the right offset between the parts. In general, this line of code would work for that:

weld.C1 = part1.CFrame:toObjectSpace(part0.CFrame)

So you'd just have to do:

local   w1 = Instance.new('Weld')
w1.Part0 = RinkakuModel.PrimaryPart
w1.Part1 = RinkakuModel.Part1
w1.C1 = RinkakuModel.Part1.CFrame:toObjectSpace(RinkakuModel.PrimaryPart.CFrame)
w.Parent = RinkakuModel.PrimaryPart

local   w2 = Instance.new('Weld')
w2.Part0 = RinkakuModel.PrimaryPart
w2.Part1 = RinkakuModel.Part2
w2.C1 = RinkakuModel.Part2.CFrame:toObjectSpace(RinkakuModel.PrimaryPart.CFrame)
w2.Parent = RinkakuModel.PrimaryPart

But, there's a lot of repetitive code that way. You could save a lot of lines using a loop to handle all of the 15 parts:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(key)
if key == "p" then

local RinkakuModel = game.ReplicatedStorage.WorkspaceRinkakuModel:Clone() --Assuming the model is now in ReplicatedStorage
local primary_part = RinkakuModel.Primary -- Since this is used a lot, let's store it in a temporary variable
RinkakuModel.PrimaryPart = primary_part

local w = Instance.new('Weld')
w.Part0 = Player.Character.Torso
w.Part1 = primary_part
w.C0 = CFrame.new(0, 10, 0)
w.Parent = Player.Character.Torso

primary_part.Anchored  = true -- Not sure if you still need to anchor it, if not you can leave it out.
for index = 1, 15 do
    local part = RinkakuModel["Part" .. index] -- This will generate Part1 till Part15
    local weld = Instance.new("Weld")
    weld.Part0 = primary_part
    weld.Part1 = part
    weld.C1 = part.CFrame:toObjectSpace(primary_part.CFrame)
    weld.Parent = primary_part
    part.Anchored = true -- Same here with the anchoring
end

-- It's probably a good idea to use SetPrimaryPartCFrame before parenting it.
RinkakuModel:SetPrimaryPartCFrame(Player.Character.Torso.CFrame * CFrame.new(0, 10, 0))
RinkakuModel.Parent = workspace
-- You don't need to use MakeJoints because you did that manually
-- RinkakuModel:MakeJoints()
RinkakuModel.Name = Player.Name

end

end)

On a side note, multiplying by CFrame.new(0, 0, 0) does nothing so I left it out. I also fixed some other minor issues.

0
Sorry but it didn't work. I ran it through the Output and it said nothing was wring with it. neoG457 315 — 9y
0
wrong* neoG457 315 — 9y
1
What aspect of it didn't seem to work? noliCAIKS 210 — 9y
0
Nothing appeared at all. neoG457 315 — 9y
1
@neoG457 I made some minor edits and fixed the problem. Sorry for messing up at first. noliCAIKS 210 — 9y
Ad

Answer this question