Attempt to index nil with 'FireClient'

Heya! Im trying to make a system which adds a stat based on a random number. However, whenever i touch the part. I get this error:

ServerScriptService.Extra.Obbies:21: attempt to index nil with 'FireClient'

Client Script

--_G.SendPet(plr, rewardList.Value)

local Player = game:GetService("Players").LocalPlayer
local ClaimButton = script.Parent:WaitForChild("ClaimButton").Button

local DB = false



game.ReplicatedStorage:WaitForChild("SystemEvents"):WaitForChild("Obby").OnClientEvent:Connect(function()
	
	local RandomReward = math.random(1,3)

	local reward = 25 * (Player.leaderstats.Rebirths.Value/2)
	reward = if reward > 0 then reward else 25

	if RandomReward == 1 then
		script.Parent.Reward.ImageLabel.Image = "rbxassetid://17342928400"
		script.Parent.Reward.RewardTitle.Text = "+20"
	elseif RandomReward == 2 then
		script.Parent.Reward.ImageLabel.Image = "rbxassetid://17353484789"
		script.Parent.Reward.RewardTitle.Text = _G.AbrevNum(reward)
	elseif RandomReward == 3 then
		script.Parent.Reward.ImageLabel.Image = "rbxassetid://17353491466"
		script.Parent.Reward.RewardTitle.Text = "35% Best"
	end
	
	ClaimButton.MouseButton1Click:Connect(function()
		if RandomReward == 1 then
	
			game:GetService("ReplicatedStorage"):WaitForChild("SystemEvents"):WaitForChild("AddStat"):FireServer(Player, "Spins", 20)
			script.Parent.Parent:Destroy()
		elseif RandomReward == 2 then
			game:GetService("ReplicatedStorage"):WaitForChild("SystemEvents"):WaitForChild("AddStat"):FireServer(Player, "Gems", reward)
			script.Parent.Parent:Destroy()
		elseif RandomReward == 3 then
			_G.SendPet(Player, "Doggy")
			script.Parent.Parent:Destroy()
		end
	end)
end)

server

local Obbies = workspace.Obbies
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:FindFirstChild("SystemEvents"):FindFirstChild("Obby")

local Cooldown = 5
local Debounce = false

ReplicatedStorage.SystemEvents.AddStat.OnServerEvent:Connect(function(Player, Stat, Amount)
	Player.leaderstats[Stat].Value = Player.leaderstats[Stat].Value + Amount
end)


Obbies.ForestObby.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if Player.PlayerGui.Main.ClaimObby then
			if Debounce == false then
				Debounce = true
				Player.PlayerGui.Main.ClaimObby.Visible = true
				Remote:FireClient(Player)
				task.wait(Cooldown)
				Debounce = false
				end
			end
		
		end
end)

Please help
Thanks!

FindFirstChild will return nil if the given instance does not exist. Since this is on the server, WaitForChild will not help as the server loads things almost instantly. So, you need to make sure that remote exists and you have the correct path to it.

1 Like

Thanks! But im not a good scripter. So im unaware of what to change

NEVERMIND! I forgot i changed the remote name and didnt update it in the scripts. :sweat_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.