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

How can I change the projectile of a raycast weapons to a different mesh?

Asked by 10 years ago

I wish to change the projectile of a tool / weapon that uses raycast in it's scripting. Heres a code snippet of the current tool's code from the original version first to my modified version that I am in the process of changing.

Original Projectile Code:

Bullet=Instance.new("Part")
Bullet.Name="Bullet"
Bullet.BrickColor=BrickColor.new("Really red")
Bullet.Anchored=true
Bullet.CanCollide=false
Bullet.Locked=true
Bullet.Size=Vector3.new(1,1,1)
Bullet.formFactor=0
Bullet.TopSurface=0
Bullet.BottomSurface=0
Bullet.Transparency = 0.5
mesh=Instance.new("BlockMesh")
mesh.Parent=Bullet
mesh.Name="Mesh"
mesh.Scale=Vector3.new(.05,.05,1

Modified Projectile Code:

Bullet=Instance.new("Part")
Bullet.Name="Lasbolt"
Bullet.BrickColor=BrickColor.new("Bright red")
Bullet.Anchored=true
Bullet.CanCollide=false
Bullet.Locked=true
Bullet.Size=Vector3.new(1,1,1)
Bullet.FormFactor=0
Bullet.TopSurface=0
Bullet.BottomSurface=0
Bullet.Transparency = 0.5
mesh=Instance.new("CylinderMesh")
mesh.Parent=Bullet
mesh.Name="Mesh"
mesh.Scale=Vector3.new(.05,.05,1)

I'm trying to change the original 'ray' projectile fired by the script into a cylinder mesh, but it doesn't seem to be working correctly. I'm really new to the world of scripting, becoming really involved after wishing to start my own clan, and I'd like some aid from more experienced veterans of ROBLOX. If there is another way to change the projectile into a cylinder mesh instead of a block one please inform me as soon as you can.

0
Please use code blocks; it's easier to read. 2eggnog 981 — 10y
0
Please put your code in a code block. A code block is the little blue Lua symbol. Put your code in the center of the two squiggly lines, leaving the squiggles each with their own line. Also make sure to tab your code correctly. Perci1 4988 — 10y
0
I put it into a code block so its easier to read. slayermaster3024 5 — 10y

1 answer

Log in to vote
0
Answered by
Sparker22 190
10 years ago

Your issue is that you never parented the original bullet brick. Instance.new() takes a second optional parameter that lets you decide where the part is parented. So if you wanted it to be in Workspace then you can set it up like this.

Bullet=Instance.new("Part", Workspace) --Added workspace as a 2nd parameter
Bullet.Name="Lasbolt"
Bullet.BrickColor=BrickColor.new("Bright red")
Bullet.Anchored=true
Bullet.CanCollide=false
Bullet.Locked=true
Bullet.Size=Vector3.new(1,1,1)
Bullet.FormFactor=0
Bullet.TopSurface=0
Bullet.BottomSurface=0
Bullet.Transparency = 0.5
mesh=Instance.new("CylinderMesh")
mesh.Parent=Bullet
mesh.Name="Mesh"
mesh.Scale=Vector3.new(.05,.05,1)

After doing that, the bullet was indeed created and you could see it. Just parent it to whatever you want it to be.

0
Can you explain a bit more in detail Sparker, as I'm not exactly familiar with scripting all too well in ROBLOX? slayermaster3024 5 — 10y
0
Alright, so your bullet is a part, correct? You need to create this part. Instance.new("Object") does this. So when you do Bullet = Instance.new("Part") you are instancing or creating a new part. This is exactly what you did in the original code. The only problem is, Lua doesn't know where to put it because you never specified where to put it. Lua defaults to nil. This means the object won't app Sparker22 190 — 10y
0
appear. So you need to specify where the project is parented to. In this case, let's say you want the object to go in Workspace. You could do Bullet = Instance.new("Part",Workspace) or do Bullet = Instance.new("Part") Bullet.Parent = Workspace Sparker22 190 — 10y
0
So in the original script when firing this raycast weapon, the ray would appear in the workspace when it had its blockmesh, however I wanted to change the mesh to a cylinder but it doesn't appear in the workspace, and this will fix the problem in the script coding? slayermaster3024 5 — 10y
View all comments (2 more)
0
Well technically the original code you provided shouldn't work because it still has no parent. Try assigning bullet a parent and see if it work. The brick should appear regardless of you inserting a block or cylinder mesh. Sparker22 190 — 10y
0
That you Sparker. slayermaster3024 5 — 10y
Ad

Answer this question