server script:

local max = 17
local debounce = true

local function updateGUI()
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	local gui = player.PlayerGui.GunGui
	gui.Enabled = true
	gui.Ammo.Value = script.Parent.Ammo.Value
	gui.Max.Value = max
	gui.GunName.Value = script.Parent.Name
	gui.GunObject.Value = script.Parent
end
script.Parent.Fire.OnServerEvent:Connect(function(plr, hit)
	print(script.Parent.Ammo.Value)
	if debounce and script.Parent.Ammo.Value ~= 0 then
		--print("BAM!")
		debounce = false
		local target = hit --script.Parent.Muzzle.CFrame.LookVector
		local ray = Ray.new(script.Parent.Muzzle.Position, target)
		local raypart = Instance.new("Part")
		raypart.Anchored = true
		raypart.Transparency = 0.8
		raypart.BrickColor = BrickColor.new("New Yeller")
		raypart.FormFactor = "Custom"
		raypart.CanCollide = false
		local Z = (ray.Origin - ray.Direction).magnitude
		raypart.Size = Vector3.new(0.01, 0.01, Z + 0.1)
		raypart.CFrame = CFrame.new(ray.Origin, ray.Direction) * CFrame.new(0, 0, -Z / 2)
		raypart.Name = "RAYPART"
		raypart.Parent = game.Workspace
		--local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent, raypart})
		local humanoid = nil
		script.Parent.GunSound:Play()
		game:GetService("Debris"):AddItem(raypart, 0.15)
		raypart.Touched:Connect(function(otherPart)
			if otherPart.Parent ~= script.Parent and otherPart.Parent ~= script.Parent.Parent and not otherPart.Parent:IsA("Accessory") then
				print("HIT")
				humanoid = otherPart.Parent:FindFirstChild("Humanoid")
				if humanoid then
					print("SHOT")
					if otherPart.Name == "Head" then
						humanoid:TakeDamage(25)
					else
						humanoid:TakeDamage(10)
					end
				end
			end
		end)
		script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
		print(script.Parent.Ammo.Value)
		updateGUI()
		script.Parent.Muzzle.Light.Enabled = true
		wait(0.1)
		script.Parent.Muzzle.Light.Enabled = false
		wait(0.4)
		debounce = true
	end
end)
script.Parent.Equipped:Connect(updateGUI)

LOCAL SCRIPT:

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
	if script.Parent.Parent:IsA("Model") then
		script.Parent.Fire:FireServer(mouse.Hit.p)
	end
end)

5 comments

0

help appreciated!

0

What do you mean shoot through acceesoress, do you mean like still damage that player if an acessory is hit? or just go thorugh a acessory?

0

Go through it,

0

Disable CanCollide on the accessories.

1

Im pretty sure you can choose what the ray ignores