generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: There's got to be a more intelligent way to weld weapons

Previous Thread :: Next Thread 
giftbox24 is not online. giftbox24
Joined: 27 Apr 2008
Total Posts: 20629
23 Aug 2014 05:36 PM
I looked at the wiki on weapon welding and it gave me something in this format. (I changed some numbers and part names)

function Weldnow()
local w1 = Instance.new("Weld")
w1.Parent = script.Parent.Handle
w1.Part0 = w1.Parent
w1.Part1 = script.Parent.Wedge1
w1.C1 = CFrame.Angles(0, 0, 0) * CFrame.new(0, -5.5, 0.2)

local w2 = Instance.new("Weld")
w2.Parent = script.Parent.Handle
w2.Part0 = w1.Parent
w2.Part1 = script.Parent.Wedge2
w2.C1 = CFrame.Angles(0, -4, 0) * CFrame.new(0, -5.5, -0.2)
end
script.Parent.Equipped:connect(Weldnow)
script.Parent.Unequipped:connect(Weldnow)

But this is really unwieldy. I've got to equip the weapon, search for it in explorer, edit the script, disable and re-enable the script, and re equip the weapon. Even then, one of the blocks might not be at the desired angle. And the numbers are really weird too. The blocks are usually like 1 degree off from what I wanted.

So I took a script from this guy, Gybron. Pretty useful, you just build the weapon the way you want it to look and put this script in the tool. It welds really well.

function Weld(x,y)
local W = Instance.new("Weld")
W.Part0 = x
W.Part1 = y
local CJ = CFrame.new(x.Position)
local C0 = x.CFrame:inverse()*CJ
local C1 = y.CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = x
end

function Get(A)
if A.className == "Part" then
Weld(script.Parent.Handle, A)
A.Anchored = false
else
local C = A:GetChildren()
for i=1, #C do
Get(C[i])
end
end
end

function Finale()
Get(script.Parent)
end

script.Parent.Equipped:connect(Finale)
script.Parent.Unequipped:connect(Finale)
Finale()

Unfortunately, tiny wedges don't seem to hold. When I equip a weapon, the wedges appear before the rest of the weapon does, and they drop to the ground.

Maybe the roblox scripting wiki's scripts are out of date. Or I'm just not understanding the cframing numbers. Is there an easier way to weld weapons?
Report Abuse
giftbox24 is not online. giftbox24
Joined: 27 Apr 2008
Total Posts: 20629
23 Aug 2014 05:55 PM
hlep
Report Abuse
vat21s is not online. vat21s
Joined: 07 Jun 2010
Total Posts: 2508
23 Aug 2014 07:07 PM
Use Union Tool
Report Abuse
vortexyamum is not online. vortexyamum
Joined: 31 Aug 2011
Total Posts: 1979
23 Aug 2014 07:51 PM
The reason you get wedges falling to the ground is because the weld script doesn't recognise them as parts. This should work:


function Weld(x,y)
local W = Instance.new("Weld")
W.Part0 = x
W.Part1 = y
local CJ = CFrame.new(x.Position)
local C0 = x.CFrame:inverse()*CJ
local C1 = y.CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = x
end

function Get(A)
if A.className == "Part" or if A.className == "WedgePart" then — This line only had "part" as a valid weldable object
Weld(script.Parent.Handle, A)
A.Anchored = false
else
local C = A:GetChildren()
for i=1, #C do
Get(C[i])
end
end
end

function Finale()
Get(script.Parent)
end

script.Parent.Equipped:connect(Finale)
script.Parent.Unequipped:connect(Finale)
Finale()
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image