My problem is that, when the gun is firing, it also fires the other gun. Only when 1 of 2 of them are equipped.
Client for both scripts:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local fireEvent = Events:WaitForChild("Fire")
local tool = script.Parent
local Details = tool:WaitForChild("Details")
local crosshair = Details:WaitForChild("Crosshair")
local fireAnim = Details:WaitForChild("Fire")
local idleAnim = Details:WaitForChild("Idle")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local debounce = false
local hold = false
local fireAnimHandler
local idleAnimHandler
function Equipped()
idleAnimHandler = char.Humanoid.Animator:LoadAnimation(idleAnim)
idleAnimHandler:Play()
mouse.Icon = crosshair.Value
end
function Activated()
if not debounce and tool.Parent == char then
fireAnimHandler = char.Humanoid.Animator:LoadAnimation(fireAnim)
fireAnimHandler:Play()
fireEvent:FireServer(mouse.Hit.LookVector)
debounce = true
task.wait(.47)
debounce = false
end
end
function Unequipped()
hold = false
mouse.Icon = "rbxasset://textures/ArrowFarCursor.png"
if idleAnimHandler or fireAnimHandler then
idleAnimHandler:Stop()
if fireAnimHandler then
fireAnimHandler:Stop()
end
end
end
tool.Equipped:Connect(Equipped)
tool.Activated:Connect(Activated)
tool.Unequipped:Connect(Unequipped)
Server for both scripts:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local fireEvent = Events:WaitForChild("Fire")
local Bullet = ReplicatedStorage:WaitForChild("Bullet")
local tool = script.Parent
fireEvent.OnServerEvent:Connect(function(plr,lookVector)
--if tool.Parent == (plr.Character or plr.CharacterAdded:Wait()) then
local bulletClone = Bullet:Clone()
bulletClone.CFrame = CFrame.new(script.Parent.MuzzleFlash.Position, (lookVector))
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = lookVector*200
bodyVelocity.Parent = bulletClone
bulletClone.CanCollide = false
bulletClone.Parent = workspace
task.spawn(function()
tool.Details.FireSound:Play()
tool.MuzzleFlash.MuzzleEffect.Enabled = true
tool.MuzzleFlash.PointLight.Enabled = true
task.wait(0.05)
tool.MuzzleFlash.MuzzleEffect.Enabled = false
tool.MuzzleFlash.PointLight.Enabled = false
end)
bulletClone.Touched:Connect(function(hit)
if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChildOfClass("Humanoid") then
if hit.Name == "Head" then
hit.Parent.Humanoid:TakeDamage(100)
else
hit.Parent.Humanoid:TakeDamage(30)
end
bulletClone:Destroy()
end
end)
--end
end)