I have this script:
function FireBullet(pos) script.Parent.Handle.LaserShot:Play() local p=Instance.new("Part") p.Parent=game.Workspace p.FormFactor="Custom" p.Size=Vector3.new(0.4,0.4,1) p.Name="LaserBullet" p.CFrame=CFrame.new(script.Parent.Handle.Position) p.TopSurface="Smooth" p.BottomSurface="Smooth" p.Color=Color3.new(0,255,0) p.CanCollide=false p.Anchored=false local l=Instance.new("PointLight") l.Parent=p l.Color=Color3.new(0,255,0) l.Shadows=true l.Range=15 local v=Instance.new("BodyVelocity") v.Parent=p v.velocity=pos-script.Parent.Handle.Position local g=Instance.new("BodyGyro") g.Parent=p local po=script.Parent.Handle.Position g.cframe=CFrame.new(Vector3.new(po.x,po.y,po.z),(CFrame.new(pos).p-Vector3.new(po.x,po.y,po.z)).unit*300) p.Touched:connect(function(part) if part.Parent:FindFirstChild("Humanoid") then if not part.Parent.Name==script.Parent.Parent.Name then script.Parent.Handle.LaserHit:Play() part.Parent.Humanoid:TakeDamage(25) p:remove() end end end) wait(10) if p.Parent==game.Workspace then p:remove() end end script.Parent.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() FireBullet(mouse.Hit.p) end) end)
I want this script to make a bullet appear at the handle of the tool, then move to where the player clicked to fire the bullet.
It should work but the only problem is that the bullet won't move after I have clicked, is there something wrong with the script? The output won't give me anything.
g.cframe=CFrame.new(Vector3.new(po.x,po.y,po.z),(CFrame.new(pos).p-Vector3.new(po.x,po.y,po.z)).unit*300)
I'm not sure if this is the only problem but you don't use vector3 with cframe. Use this instead.
g.CFrame = CFrame.new(po.x,po.y,po.z),(CFrame.new(pos).p-CFrame.new(po.x,po.y,po.z)).unit*300)