My gun script is broken sometimes?, and output says attempt to index nil with "FindFirstChild"
Asked by
1 year ago Edited 1 year ago
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