Attempt to index nil

So in my script im trying to see if a value is true or not but the script is saying Attempt to index nil with Equipped, why is this?

game.ReplicatedStorage.Events.Sell:FireServer(newchild.Coins.Value, newchild)
game.ReplicatedStorage.Events.Sell.OnServerEvent:Connect(function(player, Coins, newitem)
	player.Data.Coins.Value += Coins
	if player.Character:FindFirstChildOfClass("Model") then
		if newitem.Equipped.Value == true then --- Problem here
		print("Model has been found")
			player.Character:FindFirstChildOfClass("Model"):Destroy()
			player.Data.Damage.Value -= player.Data.EquippedValue.Value
		elseif newitem.Equipped.Value == false then
			player.Data.Damage.Value -= player.Data.EquippedValue.Value
			player.Character:FindFirstChildOfClass("Model"):Destroy()
		end
	end
end)

Most likely the item isn’t being replicated to the remoteevent probably due to the item being visible to a client only, meaning the server can’t see it, just fire in the value of Equipped and use that instead of trying to get the Equipped value from the server

game.ReplicatedStorage.Events.Sell:FireServer(newchild.Coins.Value, newchild.Equipped.Value)
game.ReplicatedStorage.Events.Sell.OnServerEvent:Connect(function(player, Coins, newitem)
	player.Data.Coins.Value += Coins
	if player.Character:FindFirstChildOfClass("Model") then
		if newitem then
		print("Model has been found")
			player.Character:FindFirstChildOfClass("Model"):Destroy()
			player.Data.Damage.Value -= player.Data.EquippedValue.Value
		else
			player.Data.Damage.Value -= player.Data.EquippedValue.Value
			player.Character:FindFirstChildOfClass("Model"):Destroy()
		end
	end
end)
1 Like

Thanks for helping, it works now

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like