I am scripting my first gun and it is a very basic gun with a mesh on the handle but I am still getting something wrong. Also I haven't scripted ammo, reloading, and so on, so this is just a firing mechanism for now. Anyways I want to make the Position of the BodyPosition the mouse.Hit because right now it is automatically setting to 0.

Inspiration taken from Friaza gun tutorial on youtube. Script is inside of handle incase you don't know the terminology of Parent and etc..

script

game.Players.PlayerAdded:connect(function(plr)
	ammo = Instance.new('NumberValue')
	ammo.Value = 6
	local mouse = plr:GetMouse()
	script.Parent.Parent.Equipped:connect(function()
		mouse.Icon = script.Parent.Parent.open.Texture
	end)
	script.Parent.Parent.Activated:connect(function(plr)
		if ammo.Value > 0 then
			local bullet = Instance.new('Part', workspace)
			bullet.Shape = "Ball"
			bullet.Size = Vector3.new(0.1, 0.1, 0.1)
			bullet.CFrame = script.Parent.CFrame+Vector3.new(0, 0.5, 0)
			bullet.Color = BrickColor.new(24).Color
			local velocity = Instance.new('BodyPosition', bullet)
			velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
			
			bullet.Anchored = false
		end
	end)
end)

3 comments

0

Filtering enabled is on(Probably), if so, then you need to learn how to use remote events.

0

link from wiki pls.

0

Just search RemoteEvents...