So i’m making a uzi and randomly it started to get this error attempt to index nil with “FindFirstChild” here is the server script:
local Char = script.Parent.Parent.Parent
script.Parent.RemoteEvents.Fire.OnServerEvent:Connect(function(Player, MousePos, Mouse)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local Raycast = workspace:Raycast(script.Parent.Part.Position,(MousePos - script.Parent.Part.Position)*300, raycastParams)
if Raycast then
script.Parent.RemoteEvents.Recoil:FireClient(Player)
local Shoot = script.Parent.Animations.Shooting
Track = Player.Character.Humanoid:LoadAnimation(Shoot)
Track:Play()
wait(0.1)
local Hit = Raycast.Instance
local Char = Hit:FindFirstAncestorOfClass("Model")
local Distance = (Raycast.Position - script.Parent.Part.Position).Magnitude
local Direction = (Raycast.Position - script.Parent.Part.Position)
local MiddlePoint = script.Parent.Part.Position + Direction/2
local light = game.ReplicatedStorage.ParticleEmitter:Clone()
light.Parent = script.Parent.Part
script.Parent.Part.SpotLight.Enabled = true
local Laser = Instance.new("Part",workspace)
Laser.Name = "Laser"
Laser.CFrame = CFrame.new(MiddlePoint,Raycast.Position)
Laser.Size = Vector3.new(0.1,0.1,Distance)
Laser.Material = Enum.Material.Neon
Laser.Parent = game.Workspace
Laser.CanCollide = false
Laser.Anchored = true
script.Parent.Ammo.Value -= 1
script.Parent.Handle.fire:Play()
if script.Parent.Ammo.Value <= 1 then
script.Parent.Ammo.Value = 0
end
Player.PlayerGui.GunGuis.Frame.Uzi.Uzi.Text = script.Parent.Ammo.Value.."/20"
script.Parent.RemoteEvents.Recoil:FireClient(Player)
if Raycast.Instance ~= nil and Raycast.Instance.Name == "Head" and (MousePos - script.Parent.Part.Position).Magnitude <= 110 then
if Raycast.Instance.Parent:FindFirstChild("Humanoid") ~= nil then
Char:FindFirstChild("Humanoid").Health -= 16
end
elseif Raycast.Instance ~= nil and Raycast.Instance.Name ~= "Head" and (MousePos - script.Parent.Part.Position).Magnitude <= 125 then
if Raycast.Instance.Parent:FindFirstChild("Humanoid") ~= nil and Raycast.Instance.Parent:FindFirstChild("Humanoid") then
Char:FindFirstChild("Humanoid").Health -= 8
end
end
if Hit.Name == "ATM" and (MousePos - script.Parent.Part.Position).Magnitude <= 125 then
Hit.Effects.MetalBullet:Play()
if Hit.Debounce.Value == false then
local ATM = Raycast.Instance
local Number = tonumber(ATM.BillboardGui.TextLabel.Text)
if Number > 1 then
Hit.Effects.MetalBullet:Play()
Number -= 1
ATM.BillboardGui.TextLabel.Text = Number
else
Hit.Debounce.Value = true
local RandomX = math.random(1, 4)
local RandomZ = math.random(1, 4)
local RandomCash = math.random(50, 100)
local Cash = game.ReplicatedStorage.Cash:Clone()
local Cash = game.ReplicatedStorage.Cash:Clone()
Cash.Parent = game.Workspace
Cash.Position = ATM.Position + Vector3.new(RandomX, 0, RandomZ)
ATM.BillboardGui.TextLabel.Text = 5
Cash.BillboardGui.TextLabel.Text = RandomCash
Cash.CashValue.Value = RandomCash
local RandomX = math.random(1, 4)
local RandomZ = math.random(1, 4)
local RandomCash = math.random(50, 100)
local Cash = game.ReplicatedStorage.Cash:Clone()
Cash.Parent = game.Workspace
Cash.Position = ATM.Position + Vector3.new(RandomX, 0, RandomZ)
ATM.BillboardGui.TextLabel.Text = 5
Cash.BillboardGui.TextLabel.Text = RandomCash
Cash.CashValue.Value = RandomCash
local RandomX = math.random(1, 4)
local RandomZ = math.random(1, 4)
local RandomCash = math.random(50, 100)
local Cash = game.ReplicatedStorage.Cash:Clone()
Cash.Parent = game.Workspace
Cash.Position = ATM.Position + Vector3.new(RandomX, 0, RandomZ)
ATM.BillboardGui.TextLabel.Text = 5
Cash.BillboardGui.TextLabel.Text = RandomCash
Cash.CashValue.Value = RandomCash
local RandomX = math.random(1, 4)
local RandomZ = math.random(1, 4)
local RandomCash = math.random(50, 100)
local Cash = game.ReplicatedStorage.Cash:Clone()
Cash.Parent = game.Workspace
Cash.Position = ATM.Position + Vector3.new(RandomX, 0, RandomZ)
ATM.BillboardGui.TextLabel.Text = 5
Cash.BillboardGui.TextLabel.Text = RandomCash
Cash.CashValue.Value = RandomCash
ATM.Effects.Smoke.Enabled = true
ATM.Effects.Sparkles.Enabled = true
wait()
Laser:Destroy()
wait(0.1)
light:Destroy()
script.Parent.Part.SpotLight.Enabled = false
wait(60)
Hit.Debounce.Value = false
ATM.Effects.Smoke.Enabled = false
ATM.Effects.Sparkles.Enabled = false
end
end
end
wait()
Laser:Destroy()
wait(0.1)
light:Destroy()
script.Parent.Part.SpotLight.Enabled = false
end
end)
script.Parent.RemoteEvents.Idle.OnServerEvent:Connect(function(Player, Anim)
Player.PlayerGui.GunGuis.Frame.Uzi.Visible = true
Player.PlayerGui.GunGuis.Frame.Visible = true
for i,v in pairs(Player.Character.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
AnimTrack = Player.Character.Humanoid:LoadAnimation(Anim)
AnimTrack:Play()
end)
script.Parent.RemoteEvents["Done Shooting"].OnServerEvent:Connect(function(Player)
for i,v in pairs(Player.Character.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
AnimTrack:Play()
end)
script.Parent.RemoteEvents.Fire.OnServerEvent:Connect(function()
AnimTrack:Stop()
end)
script.Parent.Ammo.Changed:Connect(function()
if script.Parent.Ammo.Value <= 0 then
Track:Stop()
end
end)
script.Parent.Unequipped:Connect(function()
local Player = script.Parent.Parent.Parent
Player.PlayerGui.GunGuis.Frame.Uzi.Visible = false
Player.PlayerGui.GunGuis.Frame.Visible = false
for i,v in pairs(Player.Character.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
AnimTrack:Stop()
end)
script.Parent.RemoteEvents.Reload.OnServerEvent:Connect(function(Player)
local Animation = script.Parent.Animations.Reload
local AnimationTrack = Player.Character.Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
AnimTrack:Stop()
wait(0.1)
script.Parent.Handle.GunReload:Play()
wait(1.3)
AnimTrack:Play()
wait(0.3)
Player.PlayerGui.GunGuis.Frame.Uzi.Uzi.Text = "20/20"
script.Parent.Ammo.Value = script.Parent.MaxAmmo.Value
end)
and here is the client script:
local Mouse = game.Players.LocalPlayer:GetMouse()
local Cas = game:GetService("ContextActionService")
local ReloadDebounce = false
local Debounce = false
local Camera = game.Workspace.CurrentCamera
local function Reload()
if script.Parent.Parent == game.Players.LocalPlayer.Character and ReloadDebounce == false then
ReloadDebounce = true
script.Parent.RemoteEvents.Reload:FireServer()
wait(2)
ReloadDebounce = false
end
end
script.Parent.Equipped:Connect(function()
Mouse.Icon = "http://www.roblox.com/asset/?id=4127973534"
Equipped = true
Mouse.Button1Down:Connect(function()
ButtonDown = true
while ButtonDown == true and Equipped == true and script.Parent.Ammo.Value > 0 and Debounce == false do
Debounce = true
script.Parent.RemoteEvents.Fire:FireServer(Mouse.Hit.Position, Mouse)
wait(0.1)
Debounce = false
end
if script.Parent.Ammo.Value <= 0 then
script.Parent.RemoteEvents.OutOfAmmo:FireServer()
end
end)
end)
Mouse.Button1Up:Connect(function()
ButtonDown = false
if script.Parent.Parent == game.Players.LocalPlayer.Character then
script.Parent.RemoteEvents["Done Shooting"]:FireServer()
end
end)
script.Parent.Unequipped:Connect(function()
Mouse.Icon = [[ ]]
Cas:UnbindAction("reload")
Equipped = false
end)
script.Parent.Equipped:Connect(function()
local Anim = script.Parent.Animations.Idle
script.Parent.RemoteEvents.Idle:FireServer(Anim)
Cas:BindAction("reload", Reload, true, "r")
end)
script.Parent.RemoteEvents.Recoil.OnClientEvent:Connect(function()
Camera.CFrame *= CFrame.Angles(math.rad(0.3), 0, 0)
end)
Replys is heavily appreaciated