Today while building a game with my Finnish accomplice, we ran into a bug that I have been encountering multiple times again.
So basically, I recently scripted a pistol, and we were testing it out when we noticed, that when he shot at me, I didn’t take any damage, but when I shot at him, Gore and blood was flying, and he died.
ServerScript:
local Tool = script.Parent.Parent
local Handle = Tool:FindFirstChild("Handle")
local Debris = game:GetService("Debris")
local TweenService = game:GetService("TweenService")
local Animations = Tool.Animations
local Events = Tool.Events
local Effects = Tool.Effects
local GoreSounds = game.ServerStorage.WeaponGore
local ShotHitEvent = Events.ShotHit
local Muzzle = Tool.Muzzle
local Player = Tool.Parent.Parent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character.Humanoid
local PistolModule = require(Tool.Scripts.PLConfigs)
local FireSound = Handle.Fire
local MuzzleFlash = Effects.PistolMuzzleFlash
local MuzzleFlashLight = Effects.PistolMuzzleFlashLight
local HitHumanoid = Effects.HitHumanoid
local CanFire = false
game:GetService("RunService").Stepped:Wait()
local function CastBlood(RRay, Smokey, HitPart)
local RandomSound = GoreSounds:GetChildren()
local RandomNum = math.random(1, #RandomSound)
local Sound = RandomSound[RandomNum]:Clone()
Sound.Parent = HitPart
Sound:Play()
local RayPart = Instance.new("Part")
RayPart.Transparency = 1
RayPart.Size = Vector3.new(0.1,0.1,0.1)
RayPart.Position = RRay
RayPart.Anchored = true
RayPart.CanCollide = false
RayPart.CanTouch = false
RayPart.CanQuery = false
RayPart.Parent = workspace
local CloneSmoke = Smokey:Clone()
local RandomSmokeSize = NumberSequence.new(math.random(1,2.5))
CloneSmoke.Size = RandomSmokeSize
CloneSmoke:Emit(20)
CloneSmoke.Parent = RayPart
CloneSmoke.Enabled = true
task.wait(.125)
CloneSmoke.Enabled = false
Debris:AddItem(Sound, 1)
Debris:AddItem(RayPart, .15)
--Debris:AddItem(CloneSmoke, 2)
end
local function Shoot(Plr, Target, RayPos, HitPart)
if Target then
local Humanoid = Target.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:TakeDamage(PistolModule.Damage)
CastBlood(RayPos, HitHumanoid, HitPart)
end
end
end
local function Activated()
if CanFire == false then
CanFire = true
FireSound:Play()
local MFlashClone = MuzzleFlash:Clone()
MFlashClone.Parent = Muzzle
MFlashClone.Enabled = true
Debris:AddItem(MFlashClone, .05)
local MFLightClone = MuzzleFlashLight:Clone()
MFLightClone.Parent = Muzzle
MFLightClone.Enabled = true
Debris:AddItem(MFLightClone, .05)
task.wait(PistolModule.ShotCooldown)
CanFire = false
end
end
Tool.Activated:Connect(Activated)
ShotHitEvent.OnServerEvent:Connect(Shoot)
Localscript
local Tool = script.Parent.Parent
local Handle = Tool:FindFirstChild("Handle")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Debris = game:GetService("Debris")
local Animations = Tool.Animations
local Events = Tool:WaitForChild("Events")
local Effects = Tool.Effects
local ShotHitEvent = Events.ShotHit
local Muzzle = Tool.Muzzle
local CanFire = false
local Player = game:GetService("Players").LocalPlayer
local Cursor = Player:GetMouse()
local PistolModule = require(Tool.Scripts.PLConfigs)
local LoadedPLFireAnimation = Humanoid:LoadAnimation(Animations.PistolFireAnimation)
local function Shoot()
if CanFire == false then
CanFire = true
local HitPos = Cursor.Hit.Position
local ShotOrigin = Muzzle.Position
local Direction = (HitPos - ShotOrigin).Unit
local ShotRay = workspace:Raycast(Muzzle.Position, Direction*500)
local Intersection = ShotRay and ShotRay.Position or ShotOrigin + Direction * 500
LoadedPLFireAnimation:Play()
if ShotRay then
local HitPart = ShotRay.Instance
if HitPart then
ShotHitEvent:FireServer(HitPart, ShotRay.Position, HitPart)
end
end
task.wait(PistolModule.ShotCooldown)
CanFire = false
end
end
Tool.Activated:Connect(Shoot)