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

Help understanding this code; how can it be fixed?

Asked by 8 years ago

I'm clearly having trouble getting this code to work the way I want, and I believe that's mostly because I don't understand it fully nor do I understand Lua enough to fix it...

This code was passed down to me from an old friend, but without teaching me what he knew of it.

The issue is that initially the tool begins held in hand as some nonthreatening object, then upon saying "[Weapon Name] Advance" it will turn into an actual weapon (with capability to kill while enhancing one's own power). I've gotten most of the "super power" aspects finished but for whatever reason, I fail to make the weapon held properly both visually AND physically. Here is the block of code that I mess with, followed by pictures of the entire scenario:

function CastSpell()
wand.Parent.Humanoid.Jump = false
stick.Mesh:Remove()
bullet = Instance.new("SpecialMesh")
bullet.MeshId = "http://www.roblox.com/asset/?id=62275708"
bullet.TextureId = "http://www.roblox.com/asset/?id=62275734"
bullet.Parent = stick
bullet.Scale = Vector3.new(1.5, 0.9, 1.5)
wand.GripPos = Vector3.new(0, -0.2, -1.9)
wand.GripForward = Vector3.new(-0.4472, 0.8944, 0)
wand.GripRight = Vector3.new(0.8944, 0.4472, 0)
wand.GripUp = Vector3.new(0, 0, 0)
--wand.Parent.Humanoid.WalkSpeed = 30
--wand.Parent.Humanoid.MaxHealth = 5000
--wand.Parent.Humanoid.Health = 5000
end

Here are the links to the two tools I have been experimenting with...

Dention: http://imgur.com/a/Y4Mxz

Drake: http://imgur.com/a/8fdqP

If someone could take the time to review and suggesting possible fixes, that would be much appreciated. I would also appreciate in said reviews if there was directional help, i.e., teaching me what the various Grip(x) mean as well as how Vector3 and respective variables apply to them.

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

First thing's first, you have to understand the code.

If you don't understand it, you'll never be able to:

  • add to it

  • fix bugs

  • improve efficiency

And you need to thoroughly understand it, as if you wrote it yourself. You really should write code yourself anyways, but if you don't, it's all the more important to know it better than the back of your hand. This includes understanding how everything works.


There's no actual error in your code, as far as syntax is concerned. Any problems likely arise in the Grip properties.

Basically, these properties determine how your tool is positioned. Normally, you just hold tools in the center of the handle. Grip properties offset that, so you can, say, hold a tool at the bottom of the handle, or rotate the handle around.

Vector3 is used for these properties because Roblox is 3D, so you have X, Y, and Z coordinates.

Oftentimes, the easiest way to find the correct coordinates for the Grip properties is to simply manually play around with them in studio.

0
Right, but even playing with them, I appear to be moving the handle itself so where the Mesh simply appears correctly as opposed to both of them being parallel and in-hand correctly... that's what I'm curious about and I don't know where to begin. Doom10000 5 — 8y
0
I don't understand. Of course they will move the handle around -- that's their point. Perci1 4988 — 8y
0
Sorry if my English is off; I have been changing the Vector3/Grip numbers and the result is the same... I can't have both Mesh and Brick positioned correctly (it's one or the other) and I don't know how to fix this. Doom10000 5 — 8y
0
Meshes are relative to their part, so if the brick is at the right position, the mesh should be also. Think of a roblox sword. Perci1 4988 — 8y
View all comments (3 more)
0
Okay but if you've looked at the Imgur pictures, you'll see my issue... either the mesh or the brick will be held properly and the other aspect will not be. I don't know how to fix this, do you have any suggestions on how to line up mesh and brick? Doom10000 5 — 8y
0
Oh I see, your mesh is aligned with the Z axis, or the front and back faces of the part. Simply resizing the part appropriately should fix it. Perci1 4988 — 8y
0
Okay, thanks! It worked for the two tools I've been using, ^^ The brick was floating in air but after adjusting the brick size itself, it lined up correctly! Doom10000 5 — 8y
Ad

Answer this question