I am rebuilding my gun script to work with filtering enabled. The gun works but only the shoot can see the bullets. I am not sure if the sound can be heard by the other players.
I know that I need to use a remote event.
I just don't know how to let the game know who created the bullet, where the gun was aimed, where the bullets origin should be, and what direction the bullet should fly. The current origin is gun.Main.
Thanks a lot for your help. I really do need it.
--player variables
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
--gun variables
local gun = script.Parent
if not game.workspace:FindFirstChild("Bullet") then
local bullet_storage = Instance.new("Folder", workspace)
bullet_storage.Name = "Bullet"
else
--nothing
end
function getBullet()
gun.Handle.Fire:Play()--error
local mh = mouse.Hit
local B = Instance.new("Part", workspace.Bullet)
game:GetService("Debris"):AddItem(B, 8)
B.CFrame = gun.Main.CFrame + (player.Character.Torso.CFrame.lookVector * 2)
B.CFrame = CFrame.new(B.Position, mh.p)
B.FormFactor = "Custom"
B.Size = Vector3.new(0.2, 0.2, 0.2)
B.BrickColor = BrickColor.Black()
B.CanCollide = true
local velo = Instance.new("BodyVelocity", B)
velo.velocity = B.CFrame.lookVector * 120
velo.maxForce = Vector3.new(math.huge, math.huge, math.huge)
B.Touched:connect(function(hit)
local toRespawn = game.Players:GetPlayerFromCharacter(hit.Parent)
local event = game.ReplicatedStorage:WaitForChild("FireGun"):FireServer(toRespawn)
end)
end
mouse.Button1Down:connect(function()
getBullet()
end)
