Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help me weld this to my torso?

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

Mouse.KeyDown:connect(function(key)
if key == "p" and not debounce then
debounce = true
local RinkakuModel = game.ReplicatedStorage.WorkspaceRinkakuModel:Clone() --Assuming the model is now in ReplicatedStorage
local   w = Instance.new('Weld')
w.Part0 = RinkakuModel.PrimaryPart
w.Part1 = Player.Character.Torso
w.Parent = RinkakuModel.PrimaryPart
w.C0 = CFrame.new(0, 0, 0)
RinkakuModel.Parent = Player.Character
RinkakuModel:MakeJoints()
RinkakuModel.Name = Player.Name
end
end)

It should weld RinkakuModel's primary part to my torso when I press P but instead it spawns where it was put into ReplicatedStorage. Help me get it on my torso please? The script is a localscript and "WorkspaceRinkakuModel" is in Replicated Storage (Despite the name)

1 comment

0

Neo, mine is correct. SetPrimaryPartCFrame moves the primarypart and all the other objects in the model with it.

2 answers

Just change the Models's PrimatryPart CFrame to your torso. Assuming that the model is about the size of the torso. To change the CFrame of a model do :SetPrimaryPartCFrame()

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

Mouse.KeyDown:connect(function(key)
if key == "p" and not debounce then
debounce = true
local RinkakuModel = game.ReplicatedStorage.WorkspaceRinkakuModel:Clone() --Assuming the model is now in ReplicatedStorage
local   w = Instance.new('Weld')
w.Part0 = RinkakuModel.PrimaryPart
w.Part1 = Player.Character.Torso
w.Parent = RinkakuModel.PrimaryPart
w.C0 = CFrame.new(0, 0, 0)
RinkakuModel.Parent = Player.Character
RinkakuModel:SetPrimaryPartCFrame(Player.Character.Torso.CFrame*CFrame.Angles(math.rad(Player.Character.Torso.Rotation.X),math.rad(Player.Character.Torso.Rotation.Y),math.rad(Player.Character.Torso.Rotation.Z)))
RinkakuModel:MakeJoints()
RinkakuModel.Name = Player.Name
end
end)

Hope it helps!

Game Script in ServerScript Service

game.ReplicatedStorage:FindFirstChild("RinkakuModel").PrimaryPart = game.ReplicatedStorage:FindFirstChild("RinkakuModel").Primary

local function makewelds(model,base)
local b = base or model.PrimaryPart
for i,v in pairs(model:GetChildren()) do
if #v:GetChildren() > 0 then
coroutine.resume(coroutine.create(makewelds),v,b)
end
if v:IsA("BasePart") and v ~= b then
local w = Instance.new("Weld",b)
w.Part0 = b
w.Part1 = v
w.C0 = v.CFrame - b.Position
end
end
end

makewelds(game.ReplicatedStorage:FindFirstChild("RinkakuModel"))

Local Script in StarterGui or StarterPack

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local RinkakuModel = game.ReplicatedStorage:FindFirstChild("RinkakuModel")

local m
m = mouse.KeyDown:connect(function(key)
if key == "p" then
m:disconnect()
local clone = RinkakuModel:Clone()
local w = Instance.new("Weld",clone.PrimaryPart)
w.Part0 = clone.PrimaryPart
w.Part1 = player.Character:FindFirstChild("Torso")
clone.Parent = player.Character
end
script:Destroy()
end)

5 comments

0

Still not working, maybe my surfaces arent set properly? If so how would I do this?

0

Aquathorn, http://wiki.roblox.com/index.php?title=API:Class/Model/SetPrimaryPartCFrame. Read the description. "All other parts in the model will also be moved and will maintain their orientation and offset respective to the PrimaryPart." So what you have commented was false.

0

It's still unnecessary. The weld automatically sets the CFrame of the part to the Torso, moving the rest of the model with it.

0

You can learn about how to use surface welds here: http://wiki.roblox.com/index.php?title=Brick_surface_types

0

Come try this out, I edited my answer and tested it with your model. It requires two scripts now, since you need to add welds to the initial model.

This discussion is preserved as it was. New answers, comments, and votes are closed.