All of the scripts are correct but it won't shoot for some reason.I have tried fixing it didn't help.
Gun main:
--Made by: Hirez33
--
-- November 11 2018
--[[
This script manages the raycasting of the gun
--]]
--Variables
local remote = game.ReplicatedStorage:WaitForChild("Remote"):WaitForChild("GunEvent")
--Main
remote.OnClientEvent:connect(function (player, barrelPos, mousePos)
local ray = Ray.new(barrelPos,(barrelPos - mousePos).unit * 300)
local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true)
local dist = (barrelPos - mousePos).magnitude
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(10)
end
end
remote:FireAllClients(player, part, position, barrelPos)
end)
Local script:
-- Made by: Hirez33
--
-- November 11 2018
-- [[
Local script in charge of out gun ;)
]]--
-- Variables
local gun = script.Parent
local remote = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("GunEvent")
--Main
gun.Equipped:connect(function (mouse)
mouse.Button1Down:connect(function ()
remote:FireServer(gun.Barrel.CFrame.p, mouse.Hit.p)
end)
end)
BulletGenerate:
--Made by Hirez33
--
-- November 11 2018
--[[
This script will generate the bullet for the player to see
--]]
--Variable
local remote = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("GunEvent")
--Main
remote.OnClientEvent:connect(function (player, part, position, dist, barrelPos)
local bullet = Instance.new("Part")
bullet.Anchored = true
bullet.CanCollide = false
bullet.BrickColor = player.TeamColor
bullet.Material = "Neon"
bullet.TopSurface = "Smooth"
bullet.BottomSurface = "Smooth"
bullet.Size = Vector3.new(0.3,0.3,dist)
bullet.CFrame = CFrame.new(barrelPos, position) * CFrame.new(0,0 -dist/2)
bullet.Parent = game.Workspace
game.Debris:AddItem(bullet,0.1)
end)

1 comment
I believe you have to have a MouseClick script in order for it to work.