local debounce = false
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player,hit,target)
if debounce == false then
debounce = true
local newpart = Instance.new("Part",workspace)
local dist = (hit-player.Character.HumanoidRootPart.Position).Magnitude
newpart.BrickColor = BrickColor.new("Fire Yellow")
newpart.Anchored = true
newpart.CanCollide = false
newpart.Size = Vector3.new(0.2,0.2,(hit-script.Parent.Handle.Position).Magnitude)
newpart.CFrame = CFrame.new(script.Parent.Handle.Position,hit) * CFrame.new(0,0,-dist/2)
script.Parent.Handle["Glock 21 Gunshot"]:Play()
spawn(function()
for i = 1,10 do
newpart.Transparency = i/10
if i == 10 then
newpart:Destroy()
end
wait(0.05)
end
end)
if target ~= nil then
if target.Parent:FindFirstChild("Humanoid") then
if target.Parent ~= player.Character then
target.Parent.Humanoid:TakeDamage(script.Parent.damage.Value)
end
end
end
wait(script.Parent.Firerate.Value)
debounce = false
end
end)
while wait() do
script.Parent.Firerate.Value = script.Parent.OriFirerate.Value - (script.Parent.OriFirerate.Value/100*game.Workspace.FirerateMul.Value)
script.Parent.damage.Value = script.Parent.Oridamage.Value + (script.Parent.Oridamage.Value/100*game.Workspace.DamageMul.Value)
end
COMMUNITY QUESTION
My gun script is broken sometimes?, and output says attempt to index nil with "FindFirstChild"
0 answers
No public answers were preserved for this question.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
in line 24, change it to
if target ~= nil and target.Parent ~= nil thenit's because even tho
targetexists, there's a chance that its parent doesn't exist, meaningtargethas been deletedtarget.Parent ~= nilchecks iftargethasn't been destroyed