local Tool = script.Parent.Parent
debounce = false
local Muzzle = Tool.Muzzle.PointLight
local FireSound = script:WaitForChild("FireSound")
local HitSound = script:WaitForChild("HitSound")
local CS = game:GetService("CollectionService")
local player = game.Players.LocalPlayer
game.ReplicatedStorage.RayCastEvent.OnServerEvent:Connect(function(Player,FromP,ToP)
local RayCast = Ray.new(FromP,(ToP-FromP).unit*100)
local ignore = workspace:GetChildren();
table.insert(ignore,player)
local Part = game.Workspace:FindPartOnRayWithIgnoreList(RayCast,workspace.Camera:GetDescendants())
FireSound:Play()
if Part and debounce == false then
local Hum = Part.Parent:FindFirstChild("Humanoid")
Hum:TakeDamage("20")
HitSound:Play()
Muzzle.Enabled = true
wait(0.1)
debounce = true
wait(0.1)
Muzzle.Enabled = false
debounce = false
end
end)
Edit 2 : I have fixed my old issue, now though I need to find a way to make the script ignore local player (This is problematic because you cannot find character from a server script, so, is there anyway I can make this server script make sure that the ray ignores the player who shot the gun?
This is the local part where the event is fired
local UnequipEvent = game.ReplicatedStorage.Folder.Unequipped
local EquippedEvent = game.ReplicatedStorage.Folder.Equipped
local char = script.Parent
local player = game.Players.LocalPlayer
local Character = workspace.Camera:WaitForChild("Viewmodel")
local cam = workspace.Camera
local Mouse = game.Players.LocalPlayer:GetMouse()
local humanoid = Character:WaitForChild("Humanoid")
local Run = script:WaitForChild('Run')
local Fire = script:WaitForChild('Fire')
local FireAnimTPS = script:WaitForChild('FireAnimTPS')
local Muzzle = Character.Gun.FirePart.Muzzle
local MuzzleLight = Character.Gun.FirePart.PointLight
local FireSound = script.Fire:WaitForChild("FireSound")
local Reload = script:WaitForChild('Reload')
local ReloadTPS = script:WaitForChild("ReloadAnimTPS")
local ReloadSound = script.Reload:WaitForChild("ReloadSound")
local dance = humanoid:LoadAnimation(Run)
local FireAnim = humanoid:LoadAnimation(Fire)
local FireAnimTP = player.Character.Humanoid:LoadAnimation(FireAnimTPS)
local ReloadAnim = humanoid:LoadAnimation(Reload)
local ReloadAnimTPS = player.Character.Humanoid:LoadAnimation(ReloadTPS)
local Running = false
local Shooting = false
local Ammo = game.StarterPack.Gun.Ammo.Value
local Tool = game.StarterPack.Gun
debounce = false
Fired = false
EquippedEvent.OnClientEvent:Connect(function()
Fired = true
end)
UnequipEvent.OnClientEvent:Connect(function()
Fired = false
end)
player.Character.Humanoid.Running:connect(function(speed) --I hope player is a variable of an actual player.
if speed <= 16 and humanoid.Jump == false then --If they are not walking,
dance:Stop()
Running = false
elseif speed > 18 and humanoid.Jump == false then --If they started walking or is walking.
dance:Play()
FireAnim:Stop()
MuzzleLight.Enabled = false
Running = true
end
end)
Mouse.Button1Down:Connect(function()
if Running == false and Ammo > 0 and Fired == true then
Shooting = true
print("Shooting")
FireAnimTP:Play()
FireAnim:Play()
repeat FireSound:Play() Ammo = Ammo - 1 game.Players.LocalPlayer:GetMouse().TargetFilter = game.Players.LocalPlayer.Character print(Ammo)game.ReplicatedStorage.RayCastEvent:FireServer(Tool.FirePart.Position, Mouse.Hit.Position) Muzzle.Enabled = true MuzzleLight.Enabled = true wait(0.1) Muzzle.Enabled = false until Ammo == 0 or Shooting == false or Running == true or Fired == false
if Ammo <= 0 and Fired == true then
Muzzle.Enabled = false
FireAnim:Stop()
FireAnimTP:Stop()
MuzzleLight.Enabled = false
print("All out!")
ReloadAnim:Play()
ReloadAnimTPS:Play()
ReloadSound:Play()
Character.Gun.Magazine.Transparency = 1
Character.Magazine1.Transparency = 0
wait(1.3)
Character.Magazine1.Transparency = 1
Character.Gun.Magazine.Transparency = 0
wait(1)
ReloadSound:Stop()
Ammo = 30
print("Loaded!")
end
end
end)
Mouse.Button1Up:Connect(function()
Shooting = false
print("Not Shooting")
FireAnim:Stop()
FireAnimTP:Stop()
MuzzleLight.Enabled = false
end)
player.Character.Humanoid.Died:Connect(function()
while player.Character.Humanoid.Health == 0 do
Ammo = 30
wait()
end
end)
Mouse.KeyUp:connect(function (key)
key = string.lower(key)
if string.byte(key) == 48 then
Running = false
dance:Stop()
end
end)
-- Run function
Mouse.Button2Down:Connect(function()
Character.PrimaryPart = Character.AimHumanoid
Aiming = true
end)
Mouse.Button2Up:Connect(function()
Character.PrimaryPart = Character.PartHumanoid
Aiming = false
end)

1 comment
More helpful stuff https://developer.roblox.com/en-us/api-reference/property/Mouse/TargetFilter anddd https://developer.roblox.com/en-us/api-reference/function/Workspace/FindPartOnRayWithWhitelist