Heya there.
Remaking a ROBLOX game called Noobs vs Zombies: Relish Reborn. When making the default secondary, the tracer only appears whenever hitting something and not when aiming at the sky.
Server Script
--//Tool
local Tool = script.Parent
local FireEvent = Tool:WaitForChild("FireEvent")
--Attributes
local AmmoHold = Tool:GetAttribute("Ammo_Hold")
local AmmoContain = Tool:GetAttribute("Ammo_Contain")
local Cooldown = Tool:GetAttribute("Cooldown")
--//Functionality
local CollectionService = game:GetService("CollectionService")
FireEvent.OnServerEvent:Connect(function(Player, Type, MouseHit)
local FirePos = Tool.Pistol.Position
if Type == "Fire" then
local ammoHold = Tool:GetAttribute("Ammo_Hold")
--//Getting Players' team & role.
local Self_Team = Player.Team
local TagRole = CollectionService:GetTags(Player.Character)
--//Sanity Checking
if ammoHold <= AmmoHold then --Checking to see if the amount of ammo their holding is legit.
Tool:SetAttribute("Ammo_Hold", ammoHold - 1)
--//Firing the gun
Tool.Pistol.Fire:Play()
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {Player.Character}
RayParams.FilterType = Enum.RaycastFilterType.Exclude
local Raycast = workspace:Raycast(Tool.Pistol.Position, (MouseHit - Tool.Pistol.Position).Unit * 500, RayParams)
if Raycast then
local PossiblePlayer = Raycast.Instance.Parent
--//Creating bullet tracer
local Direction = Raycast.Position
game:GetService("ReplicatedStorage").ReplicateGunTracer:FireAllClients(FirePos,Direction)
--//Checking if ray hits a player or character
local CheckPlayer = game:GetService("Players"):GetPlayerFromCharacter(PossiblePlayer)
if CheckPlayer then
local PossibleEnemyTeam = CheckPlayer.Team
if PossibleEnemyTeam ~= Self_Team then
CheckPlayer.Character.Humanoid:TakeDamage(12)
else
--If we hit an ally.
return
end
else --//If the ray a NPC instead, we can just check its tag/role to see if they're an ally or not.
local PossibleEnemyNPC = Raycast.Instance.Parent
if CollectionService:HasTag(PossibleEnemyNPC, "Noob") then
--If we hit an ally.
return
end
PossibleEnemyNPC:FindFirstChildWhichIsA("Humanoid"):TakeDamage(12)
end
else
--//Creating bullet tracer
local Direction = Tool.Pistol.Position + (MouseHit - Tool.Pistol.Position).Unit * 500
game:GetService("ReplicatedStorage").ReplicateGunTracer:FireAllClients(FirePos,Direction)
end
else -- No need to elseif unless you're chaining a bunch of conditions. Either they have ammo or they don't here.
warn("Not valid. Stop hacking, cheater.")
Tool:SetAttribute("Ammo_Hold", ammoHold - 1)
end
end
--
if Type == "Reload" then
local ammoHold = Tool:GetAttribute("Ammo_Hold")
local ammoContain = Tool:GetAttribute("Ammo_Contain")
--//Sanity checking
if ammoHold <= AmmoHold then
Tool:SetAttribute("Ammo_Hold", 12)
Tool:SetAttribute("Ammo_Contain", ammoContain - 12)
else
warn("Too much ammo. Stop hacking, cheater.")
return
end
end
end)
Module Script/Tracer Script
local TS = game:GetService("TweenService")
local defaultSettings = {
TextureSpeed = 0,
TextureLength = 1,
Texture = "rbxassetid://10822615828",
Color = ColorSequence.new(Color3.new(255, 170, 0)),
Width0 = 0.4,
Width1 = 0.4,
Transparency = NumberSequence.new(0),
LightEmission = 1,
FaceCamera = true
}
return function(Source, Point, Settings)
local Direction = (Source - Point).Unit
local Distance = (Source - Point).Magnitude
local CBullet = Instance.new("Part")
CBullet.Anchored = true
CBullet.CanCollide = false
CBullet.Size = Vector3.new(0.1, 0.1, 0.1)
CBullet.Transparency = 1
CBullet.Parent = workspace.Debris
CBullet.CFrame = CFrame.lookAt(Source, Point)
local At0 = Instance.new("Attachment")
At0.Position = Vector3.new(0, 0, 0)
At0.Parent = CBullet
local At1 = Instance.new("Attachment")
At1.Position = Vector3.new(0, 0, -Distance)
At1.Parent = CBullet
local Beam = Instance.new("Beam")
Beam.Attachment0 = At0
Beam.Attachment1 = At1
Beam.Parent = CBullet
for property, value in pairs(defaultSettings) do
Beam[property] = value
end
local Tween = TS:Create(At0, TweenInfo.new(.1, Enum.EasingStyle.Linear), {Position = At1.Position})
Tween:Play()
Tween.Completed:Wait()
--CBullet:Destroy()
end